Skip to content

Commit

Permalink
[mypyc] Report error for nested class instead of crashing (#18460)
Browse files Browse the repository at this point in the history
  • Loading branch information
svalentin authored Jan 14, 2025
1 parent a6c1184 commit ce61d11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mypyc/irbuild/classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def transform_class_def(builder: IRBuilder, cdef: ClassDef) -> None:
This is the main entry point to this module.
"""
if cdef.info not in builder.mapper.type_to_ir:
builder.error("Nested class definitions not supported", cdef.line)
return

ir = builder.mapper.type_to_ir[cdef.info]

# We do this check here because the base field of parent
Expand Down
12 changes: 12 additions & 0 deletions mypyc/test-data/irbuild-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,15 @@ class T:

class E(T):
y: str # E: Type of "y" is incompatible with definition in trait "T"


[case testNestedClasses]
def outer():
class Inner: # E: Nested class definitions not supported
pass

return Inner

if True:
class OtherInner: # E: Nested class definitions not supported
pass

0 comments on commit ce61d11

Please sign in to comment.