Skip to content

Commit

Permalink
Fix argument label of synthetic function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Jan 24, 2025
1 parent 85172b0 commit 2a13f25
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions bbq/compiler/desugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (d *Desugar) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration)

// Before the post conditions are appended, we need to move the
// return statement to the end of the function.
// For that, replace the remove with a temporary result assignment,
// and once the post conditions are added, then add a new return
// For that, replace the return-stmt with a temporary result assignment,
// and once the post conditions are added, then add a new return-stmt
// which would return the temp result.

// TODO: If 'result' variable is used in the user-code,
Expand Down Expand Up @@ -167,7 +167,7 @@ func (d *Desugar) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration)
}
}

// Once the return statement is remove, then append the post conditions.
// Once the return statement is removed, then append the post conditions.
modifiedStatements = append(modifiedStatements, postConditions...)

// Insert a return statement at the end, after post conditions.
Expand Down Expand Up @@ -257,7 +257,7 @@ func (d *Desugar) desugarConditions(
continue
}

// If the inheritted function has pre-conditions, then add an invocation
// If the inherited function has pre-conditions, then add an invocation
// to call the generated pre-condition-function of the interface.

// Generate: `FooInterface.bar.&preCondition(a1, a2)`
Expand Down Expand Up @@ -759,7 +759,7 @@ func (d *Desugar) interfaceDelegationMethodCall(
arguments := make([]*ast.Argument, 0)
for _, param := range inheritedFunc.ParameterList.Parameters {
var arg *ast.Argument
if param.Label == "" {
if param.Label == "_" {
arg = ast.NewUnlabeledArgument(
d.memoryGauge,
ast.NewIdentifierExpression(
Expand All @@ -768,9 +768,16 @@ func (d *Desugar) interfaceDelegationMethodCall(
),
)
} else {
var label string
if param.Label == "" {
label = param.Identifier.Identifier
} else {
label = param.Label
}

arg = ast.NewArgument(
d.memoryGauge,
param.Label,
label,
&param.StartPos,
&param.StartPos,
ast.NewIdentifierExpression(
Expand Down Expand Up @@ -868,7 +875,6 @@ func (d *Desugar) interfaceDelegationMethodCall(
func (d *Desugar) VisitInterfaceDeclaration(declaration *ast.InterfaceDeclaration) ast.Declaration {
interfaceType := d.elaboration.InterfaceDeclarationType(declaration)

// TODO: Fix: this will overwrite top-level declarations
prevModifiedDecls := d.modifiedDeclarations
prevEnclosingInterfaceType := d.enclosingInterfaceType
d.modifiedDeclarations = nil
Expand Down

0 comments on commit 2a13f25

Please sign in to comment.