Skip to content

typechecking of closures is bogus #10

Open

Description

@AndrewTolmach

Currently, type_check_Llambda.py treats the type of a closure as being the type of the corresponding tuple. But this makes it impossible to obtain type equality for two lambdas that have closures with different shapes. Indeed, it is well-known that type-checking closure-converted code requires existential types.

This problem has been masked partly because the test suite doesn't contain any triggers, and partly because type_check_Ltup.py currently fails to compare tuples properly (it doesn't check that they have the same length).

A test file that demonstrates the problem is:

def p() -> Callable[[int], int]:
    b = True
    x = 42
    f : Callable[[int], int] = lambda z: z if b else 1
    g : Callable[[int], int] = lambda w: w if x == 42 else 1
    return f if True else g
print(p()(42))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions