1
1
package actionlint
2
2
3
3
import (
4
+ "encoding/json"
4
5
"fmt"
5
6
"regexp"
6
7
"strconv"
@@ -786,15 +787,15 @@ func checkFuncSignature(n *FuncCallNode, sig *FuncSignature, args []ExprType) *E
786
787
return nil
787
788
}
788
789
789
- func (sema * ExprSemanticsChecker ) checkBuiltinFunctionCall (n * FuncCallNode , _ * FuncSignature ) {
790
+ func (sema * ExprSemanticsChecker ) checkBuiltinFuncCall (n * FuncCallNode , sig * FuncSignature ) ExprType {
790
791
sema .checkSpecialFunctionAvailability (n )
791
792
792
793
// Special checks for specific built-in functions
793
794
switch strings .ToLower (n .Callee ) {
794
795
case "format" :
795
796
lit , ok := n .Args [0 ].(* StringNode )
796
797
if ! ok {
797
- return
798
+ return sig . Ret
798
799
}
799
800
l := len (n .Args ) - 1 // -1 means removing first format string argument
800
801
@@ -817,7 +818,22 @@ func (sema *ExprSemanticsChecker) checkBuiltinFunctionCall(n *FuncCallNode, _ *F
817
818
for i := range holders {
818
819
sema .errorf (n , "format string %q contains placeholder {%d} but only %d arguments are given to format" , lit .Value , i , l )
819
820
}
821
+ case "fromjson" :
822
+ lit , ok := n .Args [0 ].(* StringNode )
823
+ if ! ok {
824
+ return sig .Ret
825
+ }
826
+ var v any
827
+ err := json .Unmarshal ([]byte (lit .Value ), & v )
828
+ if err == nil {
829
+ return typeOfJSONValue (v )
830
+ }
831
+ if s , ok := err .(* json.SyntaxError ); ok {
832
+ sema .errorf (lit , "broken JSON string is passed to fromJSON() at offset %d: %s" , s .Offset , s )
833
+ }
820
834
}
835
+
836
+ return sig .Ret
821
837
}
822
838
823
839
func (sema * ExprSemanticsChecker ) checkFuncCall (n * FuncCallNode ) ExprType {
@@ -844,8 +860,7 @@ func (sema *ExprSemanticsChecker) checkFuncCall(n *FuncCallNode) ExprType {
844
860
err := checkFuncSignature (n , sig , tys )
845
861
if err == nil {
846
862
// When one of overload pass type check, overload was resolved correctly
847
- sema .checkBuiltinFunctionCall (n , sig )
848
- return sig .Ret
863
+ return sema .checkBuiltinFuncCall (n , sig )
849
864
}
850
865
errs = append (errs , err )
851
866
}
0 commit comments