Skip to content

Commit ce61d11

Browse files
authored
[mypyc] Report error for nested class instead of crashing (#18460)
fixes mypyc/mypyc#864
1 parent a6c1184 commit ce61d11

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

mypyc/irbuild/classdef.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def transform_class_def(builder: IRBuilder, cdef: ClassDef) -> None:
9797
9898
This is the main entry point to this module.
9999
"""
100+
if cdef.info not in builder.mapper.type_to_ir:
101+
builder.error("Nested class definitions not supported", cdef.line)
102+
return
103+
100104
ir = builder.mapper.type_to_ir[cdef.info]
101105

102106
# We do this check here because the base field of parent

mypyc/test-data/irbuild-classes.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,3 +1300,15 @@ class T:
13001300

13011301
class E(T):
13021302
y: str # E: Type of "y" is incompatible with definition in trait "T"
1303+
1304+
1305+
[case testNestedClasses]
1306+
def outer():
1307+
class Inner: # E: Nested class definitions not supported
1308+
pass
1309+
1310+
return Inner
1311+
1312+
if True:
1313+
class OtherInner: # E: Nested class definitions not supported
1314+
pass

0 commit comments

Comments
 (0)