Skip to content

Commit b430a08

Browse files
rchen152meta-codesync[bot]
authored andcommitted
Fix var leak in LitEnum
Summary: 350bac2 added a VisitMut to LitEnum that skipped the `ty` field. This caused a Var leak that led to pyrefly crashing on the mypy_primer archinstall project. This diff deep forces types before storing them in `LitEnum` to avoid leaking vars. Fixes #3031. Reviewed By: yangdanny97 Differential Revision: D99751901 fbshipit-source-id: f8691cfea089e55b315d05dd9806b8aff289a797
1 parent 7ce1a1e commit b430a08

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

pyrefly/lib/alt/class/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
380380
Lit::Enum(Box::new(LitEnum {
381381
class: enum_.cls.clone(),
382382
member: name.clone(),
383-
ty: ty.clone(),
383+
ty: self.solver().deep_force(ty.clone()),
384384
}))
385385
.to_implicit_type(),
386386
)

pyrefly/lib/test/enums.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,3 +1015,30 @@ class Planet(float, Enum):
10151015
assert_type(Planet.MERCURY.value, float)
10161016
"#,
10171017
);
1018+
1019+
fn frozen_enum_members_env() -> TestEnv {
1020+
TestEnv::one(
1021+
"foo",
1022+
r#"
1023+
from enum import Enum
1024+
from typing import Self
1025+
class E(Enum):
1026+
A = frozenset({1})
1027+
B = frozenset({2})
1028+
@classmethod
1029+
def from_ord(cls) -> list[Self]:
1030+
return [v for v in cls]
1031+
"#,
1032+
)
1033+
}
1034+
1035+
testcase!(
1036+
test_frozen_enum_members_cross_module_iteration,
1037+
frozen_enum_members_env(),
1038+
r#"
1039+
from foo import E
1040+
def f() -> None:
1041+
xs = E.from_ord()
1042+
_ = [x for x in xs if x != E.A]
1043+
"#,
1044+
);

0 commit comments

Comments
 (0)