Skip to content

Commit

Permalink
[mypyc] Don't crash on non-inlinable final local reads (#15719)
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 committed Feb 28, 2024
1 parent 162c74d commit 9f1c90a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypyc/irbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
UnionType,
get_proper_type,
)
from mypy.util import split_target
from mypy.util import module_prefix, split_target
from mypy.visitor import ExpressionVisitor, StatementVisitor
from mypyc.common import BITMAP_BITS, SELF_NAME, TEMP_ATTR_NAME
from mypyc.crash import catch_errors
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def emit_load_final(
"""
if final_var.final_value is not None: # this is safe even for non-native names
return self.load_literal_value(final_var.final_value)
elif native:
elif native and module_prefix(self.graph, fullname):
return self.load_final_static(fullname, self.mapper.type_to_rtype(typ), line, name)
else:
return None
Expand Down
26 changes: 26 additions & 0 deletions mypyc/test-data/irbuild-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,32 @@ def foo(z):
L0:
return 1

[case testFinalLocals]
from typing import Final

def inlined() -> str:
# XXX: the final type must be declared explicitly for Var.final_value to be set.
const: Final[str] = "Oppenheimer"
return const

def local() -> str:
const: Final[str] = inlined()
return const
[out]
def inlined():
r0, const, r1 :: str
L0:
r0 = 'Oppenheimer'
const = r0
r1 = 'Oppenheimer'
return r1
def local():
r0, const :: str
L0:
r0 = inlined()
const = r0
return const

[case testDirectlyCall__bool__]
class A:
def __bool__(self) -> bool:
Expand Down

0 comments on commit 9f1c90a

Please sign in to comment.