Skip to content

Commit 9d08da5

Browse files
martindemellometa-codesync[bot]
authored andcommitted
Do not replace CInstance types with pyrefly types
Summary: If the base type binder has produced a primitive type, it is more specific than the pyrefly-generated type and should not be replaced. Reviewed By: DinoV, alexmalyshev Differential Revision: D96394235 fbshipit-source-id: 43ad6086d3cc90a4817b6e780e9807fabc9b353c
1 parent fabd337 commit 9d08da5

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

cinderx/PythonLib/cinderx/compiler/static/pyrefly_type_binder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .module_table import ModuleTable
1515
from .pyrefly_info import PyreflyTypeInfo
1616
from .type_binder import TerminalKind, TypeBinder
17-
from .types import Class
17+
from .types import CInstance, Class
1818

1919
if TYPE_CHECKING:
2020
from .compiler import Compiler
@@ -46,6 +46,13 @@ def __init__(
4646
def visit(self, node: AST, *args: object) -> NarrowingEffect | None:
4747
ret = super().visit(node, *args)
4848
if isinstance(node, ast.expr) and self._type_info is not None:
49+
# If the parent visitor already promoted a literal to a primitive
50+
# type (e.g. `x: int64 = 0` promotes 0 to int64), don't override
51+
# it with the pyrefly-inferred type.
52+
existing_type = self.get_type(node)
53+
if isinstance(existing_type, CInstance):
54+
return ret
55+
4956
declared_type = self._type_info.lookup(node, self.modules, self.type_env)
5057

5158
if declared_type is None:

0 commit comments

Comments
 (0)