Skip to content

Commit

Permalink
Fix in toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Nov 3, 2023
1 parent 32b2173 commit 43a3ad9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Binding/Binder_Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal partial class Binder
protected virtual BindingTask<BoundExpression> BindExpression(SyntaxNode syntax, ConstraintSolver constraints, DiagnosticBag diagnostics) => syntax switch
{
// NOTE: The syntax error is already reported
UnexpectedExpressionSyntax => new UntypedUnexpectedExpression(syntax),
UnexpectedExpressionSyntax => BindingTask.FromResult<BoundExpression>(new BoundUnexpectedExpression(syntax)),
GroupingExpressionSyntax grp => this.BindExpression(grp.Expression, constraints, diagnostics),
StatementExpressionSyntax stmt => this.BindStatementExpression(stmt, constraints, diagnostics),
LiteralExpressionSyntax lit => this.BindLiteralExpression(lit, constraints, diagnostics),
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Binding/Binder_Lvalue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal partial class Binder
protected virtual BindingTask<BoundLvalue> BindLvalue(SyntaxNode syntax, ConstraintSolver constraints, DiagnosticBag diagnostics) => syntax switch
{
// NOTE: The syntax error is already reported
UnexpectedExpressionSyntax => new UntypedUnexpectedLvalue(syntax),
UnexpectedExpressionSyntax => BindingTask.FromResult<BoundLvalue>(new BoundUnexpectedLvalue(syntax)),
GroupingExpressionSyntax group => this.BindLvalue(group.Expression, constraints, diagnostics),
NameExpressionSyntax name => this.BindNameLvalue(name, constraints, diagnostics),
MemberExpressionSyntax member => this.BindMemberLvalue(member, constraints, diagnostics),
Expand Down
5 changes: 3 additions & 2 deletions src/Draco.Compiler/Internal/Binding/Binder_Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ internal partial class Binder
protected virtual BindingTask<BoundStatement> BindStatement(SyntaxNode syntax, ConstraintSolver constraints, DiagnosticBag diagnostics) => syntax switch
{
// NOTE: The syntax error is already reported
UnexpectedFunctionBodySyntax or UnexpectedStatementSyntax => new BoundUnexpectedStatement(syntax),
UnexpectedFunctionBodySyntax or UnexpectedStatementSyntax =>
BindingTask.FromResult<BoundStatement>(new BoundUnexpectedStatement(syntax)),
// Ignored
ImportDeclarationSyntax => BoundNoOpStatement.Default,
ImportDeclarationSyntax => BindingTask.FromResult<BoundStatement>(BoundNoOpStatement.Default),
FunctionDeclarationSyntax func => this.BindFunctionDeclaration(func, constraints, diagnostics),
DeclarationStatementSyntax decl => this.BindStatement(decl.Declaration, constraints, diagnostics),
ExpressionStatementSyntax expr => this.BindExpressionStatement(expr, constraints, diagnostics),
Expand Down
10 changes: 10 additions & 0 deletions src/Draco.Compiler/Internal/Binding/Tasks/BindingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

namespace Draco.Compiler.Internal.Binding.Tasks;

internal static class BindingTask
{
public static BindingTask<T> FromResult<T>(T result)
{
var task = new BindingTask<T>();
task.Awaiter.SetResult(result, null);
return task;
}
}

[AsyncMethodBuilder(typeof(BindingTaskMethodBuilder<>))]
internal struct BindingTask<T>
{
Expand Down

0 comments on commit 43a3ad9

Please sign in to comment.