From 234823c51a3190514a0501dfb519a06c90bb6fe9 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 18 Mar 2022 16:52:52 +0800 Subject: [PATCH] nac3standalone: added typevar test --- nac3standalone/demo/src/typevar.py | 40 ++++++++++++++++++++++++++++++ nac3standalone/src/main.rs | 3 +++ 2 files changed, 43 insertions(+) create mode 100644 nac3standalone/demo/src/typevar.py diff --git a/nac3standalone/demo/src/typevar.py b/nac3standalone/demo/src/typevar.py new file mode 100644 index 000000000..4d37f7739 --- /dev/null +++ b/nac3standalone/demo/src/typevar.py @@ -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 + diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index bf99cafb5..fe50797a1 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -62,6 +62,9 @@ fn main() { let parser_result = parser::parse_program(&program, file_name.into()).unwrap(); for stmt in parser_result.into_iter() { + if matches!(stmt.node, StmtKind::Import { .. } | StmtKind::ImportFrom { .. }) { + continue; + } if let StmtKind::Assign { targets, value, .. } = &stmt.node { fn handle_typevar_definition( var: &Expr,