fix(checker): handle paths with no returns in functions

This commit is contained in:
2026-06-01 14:13:48 +02:00
parent 65164abadb
commit 1b66a8553d

View File

@@ -224,11 +224,14 @@ class Checker(
for arg in pos_args + args + kw_args: for arg in pos_args + args + kw_args:
env.define(arg.name, arg.type) env.define(arg.name, arg.type)
self.evaluate_block(stmt.body, env) returned: bool = self.evaluate_block(stmt.body, env)
inferred_return: Type = UnknownType() inferred_return: Type = UnknownType()
if len(env.return_types) == 1: if not returned:
inferred_return = list(env.return_types)[0] env.return_types.append(UnitType())
elif len(env.return_types) > 1: return_types: set[Type] = set(env.return_types)
if len(return_types) == 1:
inferred_return = list(return_types)[0]
elif len(return_types) > 1:
self.error( self.error(
stmt.location, stmt.location,
f"Mixed return types: {env.return_types}", f"Mixed return types: {env.return_types}",