...
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user