This commit is contained in:
nub31
2025-09-20 19:19:40 +02:00
parent ac40648c9b
commit 8660c88278
4 changed files with 59 additions and 63 deletions

View File

@@ -70,19 +70,18 @@ public sealed class TypeChecker
}
}
private Scope BeginScope(bool root)
private void BeginScope(bool root)
{
var scope = root
? _globalScope.SubScope()
: _scopes.Peek().SubScope();
_scopes.Push(scope);
return scope;
}
private Scope EndScope()
private void EndScope()
{
return _scopes.Pop();
_scopes.Pop();
}
private StructNode CheckStructDefinition(StructSyntax node)
@@ -841,13 +840,24 @@ public sealed class TypeChecker
private bool AlwaysReturns(StatementNode statement)
{
return statement switch
switch (statement)
{
ReturnNode => true,
BlockNode block => block.Statements.Count != 0 && AlwaysReturns(block.Statements.Last()),
IfNode ifNode => AlwaysReturns(ifNode.Body) && ifNode.Else.TryGetValue(out var elseStatement) ? elseStatement.Match(AlwaysReturns, AlwaysReturns) : true,
_ => false
};
case ReturnNode:
return true;
case BlockNode block:
return block.Statements.Count != 0 && AlwaysReturns(block.Statements.Last());
case IfNode ifNode:
{
if (!AlwaysReturns(ifNode.Body))
{
return false;
}
return !ifNode.Else.TryGetValue(out var elseStatement) || elseStatement.Match(AlwaysReturns, AlwaysReturns);
}
default:
return false;
}
}
private NubType ResolveType(TypeSyntax type)