facebookincubator / cinder

Cinder is Meta's internal performance-oriented production version of CPython.
https://trycinder.com
Other
3.49k stars 121 forks source link

Redeclaring variables may cause segmentation fault #53

Closed LuKuangChen closed 2 years ago

LuKuangChen commented 2 years ago

bae060e 2021-10-22

What program did you run?

from __static__ import CheckedDict

class f():
    pass

# reveal_type(f) # 'Exact[chkdict[str, int]]'

print(f["foo"])

f: CheckedDict[str, int] = CheckedDict[str, int]({'foo': 2})

What happened?

The program is type-checked and compiled, but triggers a segmentation fault at runtime.

What should have happened?

We expected two possible outcomes. But either way, the type of f shouldn't be Exact[chkdict[str, int]].

One outcome is that the program fails type checks. It is reasonable to disallow redeclaring a variable at the same scope level when the new type is not a subtype of the old type.

Another possible outcome is that Static Python catches the runtime error. In this case, the type of f should be dynamic. The local type can be type[f] and, after the redeclaration, chkdict[str, int].

carljm commented 2 years ago

Yes, this should be a static type error. Thanks for the report!

carljm commented 2 years ago

Fixed by 6939e002a6a78d065475da200c1e238583774bd4