nac3standalone: added typevar test

This commit is contained in:
pca006132 2022-03-18 16:52:52 +08:00
parent b97c016629
commit 234823c51a
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,40 @@
from typing import TypeVar, Generic
@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, x: T):
self.x = x
def foo(self):
self.x.foo()
def run() -> int32:
insta = A()
inst = C(insta)
inst.foo()
return 0

View File

@ -62,6 +62,9 @@ fn main() {
let parser_result = parser::parse_program(&program, file_name.into()).unwrap(); let parser_result = parser::parse_program(&program, file_name.into()).unwrap();
for stmt in parser_result.into_iter() { for stmt in parser_result.into_iter() {
if matches!(stmt.node, StmtKind::Import { .. } | StmtKind::ImportFrom { .. }) {
continue;
}
if let StmtKind::Assign { targets, value, .. } = &stmt.node { if let StmtKind::Assign { targets, value, .. } = &stmt.node {
fn handle_typevar_definition( fn handle_typevar_definition(
var: &Expr, var: &Expr,