diff --git a/mypyc/irbuild/builder.py b/mypyc/irbuild/builder.py index f37fae608083..5e1ea52eb9a0 100644 --- a/mypyc/irbuild/builder.py +++ b/mypyc/irbuild/builder.py @@ -41,6 +41,7 @@ Statement, SymbolNode, TupleExpr, + TypeAlias, TypeInfo, UnaryExpr, Var, @@ -1018,7 +1019,8 @@ def call_refexpr_with_args( # Handle data-driven special-cased primitive call ops. if callee.fullname and expr.arg_kinds == [ARG_POS] * len(arg_values): - call_c_ops_candidates = function_ops.get(callee.fullname, []) + fullname = get_call_target_fullname(callee) + call_c_ops_candidates = function_ops.get(fullname, []) target = self.builder.matching_call_c( call_c_ops_candidates, arg_values, expr.line, self.node_type(expr) ) @@ -1349,3 +1351,12 @@ def remangle_redefinition_name(name: str) -> str: lookups. """ return name.replace("'", "__redef__") + + +def get_call_target_fullname(ref: RefExpr) -> str: + if isinstance(ref.node, TypeAlias): + # Resolve simple type aliases. In calls they evaluate to the type they point to. + target = get_proper_type(ref.node.target) + if isinstance(target, Instance): + return target.type.fullname + return ref.fullname diff --git a/mypyc/test-data/irbuild-lists.test b/mypyc/test-data/irbuild-lists.test index cb9687a2f942..eaeff9432446 100644 --- a/mypyc/test-data/irbuild-lists.test +++ b/mypyc/test-data/irbuild-lists.test @@ -84,6 +84,22 @@ L0: x = r0 return 1 +[case testNewListEmptyViaAlias] +from typing import List + +ListAlias = list + +def f() -> None: + x: List[int] = ListAlias() + +[out] +def f(): + r0, x :: list +L0: + r0 = PyList_New(0) + x = r0 + return 1 + [case testNewListTwoItems] from typing import List def f() -> None: