Compare commits

...

2 Commits

Author SHA1 Message Date
dd126f2559 fix(cli): improve diagnostic message popup 2026-06-01 14:48:24 +02:00
4151f5373d fix(checker): early define fully-typed function
to handle simple recursion cases where the function has an explicit return type hint, the function must be defined before evaluating its body
2026-06-01 14:40:42 +02:00
3 changed files with 30 additions and 5 deletions

View File

@@ -6,4 +6,9 @@ def minimum(x: int, y: int):
a = 15
b = 72
c = minimum(a, b)
c = minimum(a, b)
def factorial(n: int) -> int:
if n <= 1:
return 1
return n * factorial(n - 1)

View File

@@ -223,6 +223,19 @@ class Checker(
for arg in pos_args + args + kw_args:
env.define(arg.name, arg.type)
returns_hint: Optional[Type] = None
if stmt.returns is not None:
returns_hint = stmt.returns.accept(self)
# Early define to handle simple fully-typed recursion
inside_function: Function = Function(
name=stmt.name,
pos_args=pos_args,
args=args,
kw_args=kw_args,
returns=returns_hint,
)
self.env.define(stmt.name, inside_function)
returned: bool = self.evaluate_block(stmt.body, env)
inferred_return: Type = UnknownType()
@@ -236,9 +249,11 @@ class Checker(
stmt.location,
f"Mixed return types: {env.return_types}",
)
returns: Type = UnknownType()
if stmt.returns is not None:
returns = stmt.returns.accept(self)
if returns_hint is not None:
assert stmt.returns is not None
returns = returns_hint
if returns != inferred_return:
self.error(
stmt.returns.location,

View File

@@ -13,9 +13,14 @@ span {
&.with-msg {
position: relative;
&:not(:hover) {
.message {
display: none;
}
&:hover:not(:has(.with-msg:hover)) {
.message {
display: none;
display: inline-block;
}
}