fix Type::cycle_normalized

This commit is contained in:
Shunsuke Shibayama 2025-12-18 20:14:45 +09:00
parent c5bd2cde55
commit 1d1afaa517
3 changed files with 24 additions and 2 deletions

View file

@ -70,3 +70,24 @@ def descent(x: int, y: int):
def count_set_bits(n):
return 1 + count_set_bits(n & n - 1) if n else 0
class Literal:
def __invert__(self):
return Literal()
class OR:
def __invert__(self):
return AND()
class AND:
def __invert__(self):
return OR()
def to_NNF(cond):
if cond:
return ~to_NNF(cond)
if cond:
return OR()
if cond:
return AND()
return Literal()

View file

@ -429,7 +429,7 @@ def list_int(x: int):
return list1(x)
# TODO: should be `list[int]`
reveal_type(list_int(1)) # revealed: list[Divergent] | list[int] | list[Divergent]
reveal_type(list_int(1)) # revealed: list[Divergent] | list[Divergent] | list[int]
def tuple_obj(cond: bool):
if cond:

View file

@ -966,7 +966,8 @@ impl<'db> Type<'db> {
if has_divergent_type_in_cycle(previous) && !has_divergent_type_in_cycle(self) {
self
} else {
UnionType::from_elements_cycle_recovery(db, [self, previous])
// The current type is unioned to the previous type. Unioning in the reverse order can cause the fixed-point iterations to converge slowly or even fail.
UnionType::from_elements_cycle_recovery(db, [previous, self])
}
}
}