@@ -4,6 +4,15 @@ import (
44 "errors"
55)
66
7+ func valueCanContainBuiltins (val Value ) bool {
8+ switch val .Kind () {
9+ case KindBuiltin , KindArray , KindHash , KindObject , KindClass , KindInstance :
10+ return true
11+ default :
12+ return false
13+ }
14+ }
15+
716func (exec * Execution ) autoInvokeIfNeeded (expr Expression , val Value , receiver Value ) (Value , error ) {
817 switch val .Kind () {
918 case KindFunction :
@@ -39,18 +48,21 @@ func (exec *Execution) invokeCallable(callee Value, receiver Value, args []Value
3948 scope := exec .capabilityContractScopes [builtin ]
4049 var preCallKnownBuiltins map [* Builtin ]struct {}
4150 if scope != nil && len (scope .contracts ) > 0 {
42- preCallKnownBuiltins = make ( map [ * Builtin ] struct {})
51+ preCallKnownBuiltins = scope . knownBuiltins
4352 preCallScanner := newCapabilityContractScanner ()
44- if receiver . Kind () != KindNil {
53+ if valueCanContainBuiltins ( receiver ) {
4554 preCallScanner .collectBuiltins (receiver , preCallKnownBuiltins )
4655 }
47- for _ , root := range scope .roots {
48- preCallScanner .collectBuiltins (root , preCallKnownBuiltins )
49- }
5056 for _ , arg := range args {
57+ if ! valueCanContainBuiltins (arg ) {
58+ continue
59+ }
5160 preCallScanner .collectBuiltins (arg , preCallKnownBuiltins )
5261 }
5362 for _ , kwarg := range kwargs {
63+ if ! valueCanContainBuiltins (kwarg ) {
64+ continue
65+ }
5466 preCallScanner .collectBuiltins (kwarg , preCallKnownBuiltins )
5567 }
5668 }
@@ -94,9 +106,15 @@ func (exec *Execution) invokeCallable(callee Value, receiver Value, args []Value
94106 // Methods can also publish builtins by mutating positional or keyword
95107 // argument objects supplied by script code.
96108 for _ , arg := range args {
109+ if ! valueCanContainBuiltins (arg ) {
110+ continue
111+ }
97112 postCallScanner .bindContracts (arg , scope , exec .capabilityContracts , exec .capabilityContractScopes )
98113 }
99114 for _ , kwarg := range kwargs {
115+ if ! valueCanContainBuiltins (kwarg ) {
116+ continue
117+ }
100118 postCallScanner .bindContracts (kwarg , scope , exec .capabilityContracts , exec .capabilityContractScopes )
101119 }
102120 }
0 commit comments