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 · 1 comment
Open

Inheritance breaks Optional #554

Tenchi2xh opened this issue Apr 28, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

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
@inumanag inumanag added the bug Something isn't working label Sep 23, 2024
@inumanag
Copy link
Contributor

Looks like a bug. Will take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants