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

Inheritance breaks Optional #554

Open
Tenchi2xh opened this issue Apr 28, 2024 · 0 comments
Open

Inheritance breaks Optional #554

Tenchi2xh opened this issue Apr 28, 2024 · 0 comments
Assignees

Comments

@Tenchi2xh
Copy link

Tenchi2xh commented Apr 28, 2024

In the following code, foo has an Optional[A] argument and does a check on it to see if is None or defined:

class A:
    pass

def foo(maybe_a: Optional[A]):
    if maybe_a:
        print("maybe_a is defined")

foo(A())

This works, and correctly prints "maybe_a is defined".

However, if class a class B is defined and inherits from A, the exact same code will break at compile time:

class A:
    pass

class B(A):
    pass

def foo(maybe_a: Optional[A]):
    if maybe_a:
        print("maybe_a is defined")

foo(A())
internal.codon:364:16-49: error: '__internal__' object has no method 'class_raw_rtti_ptr' with arguments ()
├─ optional.codon:25:20-53: error: during the realization of opt_ref_bool_rtti(what: Optional[class_ctr[...,...]], T: class_ctr[...,...])
├─ optional.codon:43:16-30: error: during the realization of __has__(self: Optional[A])
├─ test.py:8:5-54: error: during the realization of __bool__(self: Optional[A])
╰─ test.py:11:1-4: error: during the realization of foo(maybe_a: Optional[A])

This breaks also with other types of checks: maybe_a is not None and maybe_a != None

@Tenchi2xh Tenchi2xh changed the title Inheritence breaks Optional Inheritance breaks Optional Apr 28, 2024
Tenchi2xh added a commit to Tenchi2xh/RTOW-Codon that referenced this issue Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants