fix(checker): allow subtypes and unknown as if test
This commit is contained in:
@@ -439,8 +439,10 @@ class PythonTyper(
|
|||||||
# print(m) # <- m is still defined
|
# print(m) # <- m is still defined
|
||||||
test_type: Type = self.type_of(stmt.test)
|
test_type: Type = self.type_of(stmt.test)
|
||||||
|
|
||||||
# TODO Allow subtypes or any type
|
if (
|
||||||
if test_type != self.types.get_type("bool"):
|
not self.types.is_subtype(test_type, self.types.get_type("bool"))
|
||||||
|
and test_type != UnknownType()
|
||||||
|
):
|
||||||
self.reporter.error(
|
self.reporter.error(
|
||||||
stmt.test.location, f"If test must be a boolean, got {test_type}"
|
stmt.test.location, f"If test must be a boolean, got {test_type}"
|
||||||
)
|
)
|
||||||
@@ -638,7 +640,10 @@ class PythonTyper(
|
|||||||
test_type: Type = self.type_of(expr.test)
|
test_type: Type = self.type_of(expr.test)
|
||||||
|
|
||||||
# TODO Allow subtypes or any type
|
# TODO Allow subtypes or any type
|
||||||
if test_type != self.types.get_type("bool"):
|
if (
|
||||||
|
not self.is_subtype(test_type, self.types.get_type("bool"))
|
||||||
|
and test_type != UnknownType()
|
||||||
|
):
|
||||||
self.reporter.error(
|
self.reporter.error(
|
||||||
expr.test.location, f"If test must be a boolean, got {test_type}"
|
expr.test.location, f"If test must be a boolean, got {test_type}"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user