mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 08:51:01 +02:00
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:
parent
c7a5b68f1c
commit
7c8f4d0b12
@ -444,6 +444,9 @@ const (
|
||||
ObjectFieldExpr // '['expr1']':[:[:]] expr2
|
||||
ObjectFieldStr // expr1:[:[:]] expr2
|
||||
ObjectLocal // local id = expr2
|
||||
ObjectNullID // null id
|
||||
ObjectNullExpr // null '['expr1']'
|
||||
ObjectNullStr // null expr1
|
||||
)
|
||||
|
||||
type ObjectFieldHide int
|
||||
|
@ -942,22 +942,20 @@ func evaluateAux(i *interpreter, node ast.Node, tla vmExtMap) (value, *TraceElem
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(tla) != 0 {
|
||||
// If it's not a function, ignore TLA
|
||||
if f, ok := result.(*valueFunction); ok {
|
||||
toplevelArgMap := prepareExtVars(i, tla, "top-level-arg")
|
||||
args := callArguments{}
|
||||
for argName, pv := range toplevelArgMap {
|
||||
args.named = append(args.named, namedCallArgument{name: ast.Identifier(argName), pv: pv})
|
||||
}
|
||||
funcLoc := ast.MakeLocationRangeMessage("Top-level function")
|
||||
funcTrace := &TraceElement{
|
||||
loc: &funcLoc,
|
||||
}
|
||||
result, err = f.call(args).getValue(i, funcTrace)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// If it's not a function, ignore TLA
|
||||
if f, ok := result.(*valueFunction); ok {
|
||||
toplevelArgMap := prepareExtVars(i, tla, "top-level-arg")
|
||||
args := callArguments{}
|
||||
for argName, pv := range toplevelArgMap {
|
||||
args.named = append(args.named, namedCallArgument{name: ast.Identifier(argName), pv: pv})
|
||||
}
|
||||
funcLoc := ast.MakeLocationRangeMessage("Top-level function")
|
||||
funcTrace := &TraceElement{
|
||||
loc: &funcLoc,
|
||||
}
|
||||
result, err = f.call(args).getValue(i, funcTrace)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
manifestationLoc := ast.MakeLocationRangeMessage("During manifestation")
|
||||
|
3
testdata/function_manifested.jsonnet
vendored
Normal file
3
testdata/function_manifested.jsonnet
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
f(x): 3,
|
||||
}
|
1
testdata/function_no_params.golden
vendored
Normal file
1
testdata/function_no_params.golden
vendored
Normal file
@ -0,0 +1 @@
|
||||
42
|
5
testdata/function_too_many_params.golden
vendored
Normal file
5
testdata/function_too_many_params.golden
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
RUNTIME ERROR: Missing argument: x
|
||||
-------------------------------------------------
|
||||
Top-level function
|
||||
|
||||
|
1
testdata/function_too_many_params.jsonnet
vendored
Normal file
1
testdata/function_too_many_params.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
||||
function(x) 3
|
Loading…
x
Reference in New Issue
Block a user