node: remove throw "" -> errors.New("") transform, as PHP cannot throw scalars

This commit is contained in:
mappu 2020-04-07 22:52:12 +12:00
parent d6cd0e8191
commit 0d7024dbee

10
node.go
View File

@ -355,12 +355,12 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
// Treat as an err return // Treat as an err return
// FIXME we don't know the default return type for the function we're in // FIXME we don't know the default return type for the function we're in
// If the expr is a string literal, we can convert it to errors.New() // PHP can only throw objects, not literals/scalars
// Although we probably can't do this in general for stringly-typed expressions // If the expr is just new Exception, we can convert it to errors.New()
if str, ok := n.Expr.(*scalar.String); ok { //if str, ok := n.Expr.(*scalar.String); ok {
return "return nil, errors.New(" + str.Value + ")\n", nil // return "return nil, errors.New(" + str.Value + ")\n", nil
} //}
child, err := this.convert(n.Expr) child, err := this.convert(n.Expr)
if err != nil { if err != nil {