stmt: add failing test for assignment expressions (need hoisting)
This commit is contained in:
parent
628e4c1781
commit
2568412a50
@ -34,6 +34,9 @@ The goal is to produce idiomatic, maintainable Go code as part of a one-off conv
|
||||
[ ] `instanceof`
|
||||
[ ] `try`/`catch`/`finally`
|
||||
[ ] Abandon upon sight of `eval` / `extract` / ...
|
||||
[ ] Assignment expressions
|
||||
- Go doesn't support assignment in rvalues, only as a statement
|
||||
- When walking below stmt level, need to first fully walk and check for any function calls + assignments that may need hoisting (and we can probably only do that correctly if there is no short-circuiting)
|
||||
[ ] Closures
|
||||
- [ ] Handle value/reference captures
|
||||
[ ] Sort callbacks
|
||||
|
11
fixtures/0006-expression-assignment.php
Normal file
11
fixtures/0006-expression-assignment.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
function Bar(): ?\stdClass {
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
if ( ($f = Bar()) !== null) {
|
||||
var_dump($f);
|
||||
} else {
|
||||
echo "x\n";
|
||||
}
|
9
node.go
9
node.go
@ -968,11 +968,20 @@ func (this *conversionState) convertBinaryCommon(left, right node.Node, goBinary
|
||||
if err != nil {
|
||||
return "", parseErr{left, err}
|
||||
}
|
||||
|
||||
rhs, err := this.convert(right)
|
||||
if err != nil {
|
||||
return "", parseErr{right, err}
|
||||
}
|
||||
|
||||
// In case of an rvalue assignment expression, we need extra parens
|
||||
if _, ok := left.(*assign.Assign); ok {
|
||||
lhs = "(" + lhs + ")"
|
||||
}
|
||||
if _, ok := right.(*assign.Assign); ok {
|
||||
rhs = "(" + rhs + ")"
|
||||
}
|
||||
|
||||
return "(" + lhs + " " + goBinaryOperator + " " + rhs + ")", nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user