internal error with typevar #220

Closed
opened 2022-03-17 21:28:32 +08:00 by sb10q · 1 comment
Owner
@extern
def output_int32(x: int32):
    ...

class A:
    def __init__(self):
        pass

    def foo(self):
        output_int32(1)

class B:
    def __init__(self):
        pass

    def foo(self):
        output_int32(2)


T = TypeVar("T", A, B)


class C(Generic[T]):
    x: T

    def __init__(self):
        self.x = A()

    def foo(self):
        x.foo()


def run() -> int32:
    inst = C()
    inst.foo()
    return 0
> ./run_demo.sh src/classes.py
thread 'main' panicked at 'internal error: entered unreachable code: must be type var here', nac3core/src/toplevel/composer.rs:1703:49
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```python @extern def output_int32(x: int32): ... class A: def __init__(self): pass def foo(self): output_int32(1) class B: def __init__(self): pass def foo(self): output_int32(2) T = TypeVar("T", A, B) class C(Generic[T]): x: T def __init__(self): self.x = A() def foo(self): x.foo() def run() -> int32: inst = C() inst.foo() return 0 ``` ``` > ./run_demo.sh src/classes.py thread 'main' panicked at 'internal error: entered unreachable code: must be type var here', nac3core/src/toplevel/composer.rs:1703:49 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```
Contributor

Actually this code is invalid, we should have x: A instead of x: T. If you need x: T, you should do

def __init__(self, x: T):
    self.x = x
Actually this code is invalid, we should have `x: A` instead of `x: T`. If you need `x: T`, you should do ```python def __init__(self, x: T): self.x = x ```
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#220
No description provided.