node: add bailout cases for eval() and extract()

This commit is contained in:
mappu 2020-04-15 19:06:09 +12:00
parent 2fdd3a919c
commit 9253058a73

11
node.go
View File

@ -14,6 +14,8 @@ import (
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/node/stmt"
"php2go/parseutil"
)
func nodeTypeString(n node.Node) string {
@ -1192,6 +1194,10 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
callParams = append(callParams, `-1`) // replaceAll
// There is a strings.ReplaceAll() added in go1.12 (2018), which is still pretty recent i.e. not in Debian Stable (buster)
}
} else if funcName == `extract` {
return "", parseErr{n, fmt.Errorf("Unsupported dynamic function `\\extract()`")}
}
return funcName + "(" + strings.Join(callParams, ", ") + ")", nil // expr only, no semicolon/newline
@ -1320,6 +1326,9 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
return "os.Exit(" + child + ")", nil
}
case *expr.Eval:
return "", parseErr{n, fmt.Errorf("Unsupported use of eval()")}
case *expr.PreInc:
// """In Go, i++ is a statement, not an expression. So you can't use its value in another expression such as a function call."""
v, err := this.convert(n.Variable)
@ -2105,7 +2114,7 @@ func (this *conversionState) convertFunctionCommon(params []node.Node, returnTyp
// any assignment expressions
func hasInteriorAssignment(n node.Node) (hasAnyAssign bool, err error) {
err = walk(n, func(n node.Node) error {
err = parseutil.SimpleWalk(n, func(n node.Node) error {
if _, ok := n.(*assign.Assign); ok {
hasAnyAssign = true
}