Skip to content

Commit 92d8315

Browse files
authored
[mypyc] Fix cross-group constructor calls to cached non-native classes (#22069)
This was broken when using incremental builds.
1 parent bc2b303 commit 92d8315

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎mypyc/irbuild/prepare.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ def load_type_map(mapper: Mapper, modules: list[MypyFile], deser_ctx: DeserMaps)
210210
continue
211211
mapper.type_to_ir[node.node] = ir
212212
mapper.symbol_fullnames.add(node.node.fullname)
213-
# Trait/builtin-base classes have an ir.ctor FuncDecl
214-
# but no emitted CPyDef_<ctor>, so a cross-group direct
215-
# call would hit an undefined symbol. Mirror the skip
216-
# in prepare_init_method.
217-
if not ir.is_trait and not ir.builtin_base:
213+
# Non-extension, trait and builtin-base classes have no
214+
# emitted CPyDef_<ctor>, so a cross-group direct call
215+
# would hit an undefined symbol. Mirror the conditions
216+
# under which prepare_init_method registers a ctor.
217+
if ir.is_ext_class and not ir.is_trait and not ir.builtin_base:
218218
mapper.func_to_decl[node.node] = ir.ctor
219219

220220
for module in modules:

‎mypyc/test-data/run-multimodule.test‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,27 @@ import native
14211421
0
14221422
None
14231423

1424+
[case testIncrementalCompilationWithNonExtClass]
1425+
import other_a
1426+
[file other_a.py]
1427+
from other_b import C
1428+
[file other_a.py.2]
1429+
from other_b import C
1430+
c = C(5)
1431+
print(c.x)
1432+
[file other_b.py]
1433+
from mypy_extensions import mypyc_attr
1434+
1435+
@mypyc_attr(native_class=False)
1436+
class C:
1437+
def __init__(self, x: int) -> None:
1438+
self.x = x
1439+
[file driver.py]
1440+
import native
1441+
[out]
1442+
[out2]
1443+
5
1444+
14241445
[case testIncrementalCompilationWithNonClassTypeDef]
14251446
import other_a
14261447
[file other_a.py]

0 commit comments

Comments
 (0)