Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsound static-to-static field overrides #39

Closed
LuKuangChen opened this issue Jul 15, 2021 · 2 comments
Closed

unsound static-to-static field overrides #39

LuKuangChen opened this issue Jul 15, 2021 · 2 comments
Labels
sp-correctness static python correctness staticpython static python issues

Comments

@LuKuangChen
Copy link

What version of Static Python are you using?

9965302
2021-07-15

What program did you run?

# override_field_incompatible_type.py
from typing import ClassVar

class C:
    x: ClassVar[int] = 0

class D(C):
    x: ClassVar[str] = "0"

# Interestingly, `D.x = "hello"` raises a compile-time error
# 
#     compiler.static.TypedSyntaxError: type mismatch: Exact[str] 
#     cannot be assigned to int

What happened?

The program terminates without errors.

What should have happened?

We expected a compile-time error because D override the class variable x with an incompatible type.

@jbower-fb jbower-fb added sp-correctness static python correctness staticpython static python issues labels Jul 28, 2021
@LuKuangChen
Copy link
Author

We noticed that instance fields have a similar issue. The following program passes type check. If the last line is uncommented, a compile-time error will be reported. This shows that the x: str in the subclass D is ignored. It might be more sensible to error at the re-declaration, instead of to ignore it silently.

class C:
    x: int

class D(C):
    x: str

# D().x = "foo" # compile-time type error. int is expected.

@DinoV
Copy link
Contributor

DinoV commented Dec 20, 2021

Looks like this got fixed with commit 1475ebd

@DinoV DinoV closed this as completed Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sp-correctness static python correctness staticpython static python issues
Projects
None yet
Development

No branches or pull requests

3 participants