Call top level function even if there are no TLAs (match cpp semantics) (#169)

* Call top level function even if there are no TLAs (match cpp semantics)
This commit is contained in:
Dave Cunningham 2018-01-10 20:43:55 -05:00 committed by GitHub
parent c7a5b68f1c
commit 7c8f4d0b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 16 deletions

View File

@ -444,6 +444,9 @@ const (
ObjectFieldExpr // '['expr1']':[:[:]] expr2 ObjectFieldExpr // '['expr1']':[:[:]] expr2
ObjectFieldStr // expr1:[:[:]] expr2 ObjectFieldStr // expr1:[:[:]] expr2
ObjectLocal // local id = expr2 ObjectLocal // local id = expr2
ObjectNullID // null id
ObjectNullExpr // null '['expr1']'
ObjectNullStr // null expr1
) )
type ObjectFieldHide int type ObjectFieldHide int

View File

@ -942,22 +942,20 @@ func evaluateAux(i *interpreter, node ast.Node, tla vmExtMap) (value, *TraceElem
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
if len(tla) != 0 { // If it's not a function, ignore TLA
// If it's not a function, ignore TLA if f, ok := result.(*valueFunction); ok {
if f, ok := result.(*valueFunction); ok { toplevelArgMap := prepareExtVars(i, tla, "top-level-arg")
toplevelArgMap := prepareExtVars(i, tla, "top-level-arg") args := callArguments{}
args := callArguments{} for argName, pv := range toplevelArgMap {
for argName, pv := range toplevelArgMap { args.named = append(args.named, namedCallArgument{name: ast.Identifier(argName), pv: pv})
args.named = append(args.named, namedCallArgument{name: ast.Identifier(argName), pv: pv}) }
} funcLoc := ast.MakeLocationRangeMessage("Top-level function")
funcLoc := ast.MakeLocationRangeMessage("Top-level function") funcTrace := &TraceElement{
funcTrace := &TraceElement{ loc: &funcLoc,
loc: &funcLoc, }
} result, err = f.call(args).getValue(i, funcTrace)
result, err = f.call(args).getValue(i, funcTrace) if err != nil {
if err != nil { return nil, nil, err
return nil, nil, err
}
} }
} }
manifestationLoc := ast.MakeLocationRangeMessage("During manifestation") manifestationLoc := ast.MakeLocationRangeMessage("During manifestation")

3
testdata/function_manifested.jsonnet vendored Normal file
View File

@ -0,0 +1,3 @@
{
f(x): 3,
}

1
testdata/function_no_params.golden vendored Normal file
View File

@ -0,0 +1 @@
42

View File

@ -0,0 +1,5 @@
RUNTIME ERROR: Missing argument: x
-------------------------------------------------
Top-level function

View File

@ -0,0 +1 @@
function(x) 3