Skip to content

Commit cc0dc47

Browse files
committed
Fix #371: Cannot use yield in ternary operator.
1 parent 65f3af7 commit cc0dc47

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

jphp-core/src/org/develnext/jphp/core/syntax/generators/manually/SimpleExprGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.develnext.jphp.core.tokenizer.token.SemicolonToken;
1515
import org.develnext.jphp.core.tokenizer.token.Token;
1616
import org.develnext.jphp.core.tokenizer.token.expr.*;
17+
import org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken.Kind;
1718
import org.develnext.jphp.core.tokenizer.token.expr.operator.*;
1819
import org.develnext.jphp.core.tokenizer.token.expr.operator.cast.CastExprToken;
1920
import org.develnext.jphp.core.tokenizer.token.expr.operator.cast.UnsetCastExprToken;
@@ -508,7 +509,7 @@ protected CallExprToken processCall(Token previous, Token current, ListIterator<
508509
return result;
509510
}
510511

511-
protected Token processYield(Token current, Token next, ListIterator<Token> iterator, BraceExprToken.Kind closedBrace) {
512+
protected Token processYield(Token current, Token next, ListIterator<Token> iterator, Separator separator, Kind closedBrace) {
512513
if (analyzer.getFunction() == null) {
513514
analyzer.getEnvironment().error(
514515
current.toTraceInfo(analyzer.getContext()), Messages.ERR_YIELD_CAN_ONLY_INSIDE_FUNCTION.fetch()
@@ -529,7 +530,7 @@ protected Token processYield(Token current, Token next, ListIterator<Token> iter
529530
result.setValue(null);
530531
} else {
531532
ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getNextExpression(
532-
nextToken(iterator), iterator, BraceExprToken.Kind.ANY
533+
nextToken(iterator), iterator, separator, BraceExprToken.Kind.ANY
533534
);
534535
result.setValue(value);
535536
}
@@ -1025,7 +1026,7 @@ protected Token processSimpleToken(Token current, Token previous, Token next, Li
10251026
}
10261027

10271028
if (current instanceof YieldExprToken) {
1028-
return processYield(current, next, iterator, closedBraceKind);
1029+
return processYield(current, next, iterator, separator, closedBraceKind);
10291030
}
10301031

10311032
if (current instanceof ImportExprToken) {

jphp-core/tests/org/develnext/jphp/core/compiler/jvm/GeneratorsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,9 @@ public void testBug262() {
223223
public void testBug369() {
224224
check("generators/bug369.phpt");
225225
}
226+
227+
@Test
228+
public void testBug371() {
229+
check("generators/bug371.phpt");
230+
}
226231
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test yield syntax in ternary operator
3+
--FILE--
4+
<?php
5+
6+
function a() {
7+
true ? yield : yield;
8+
true ?: yield;
9+
true ?? yield;
10+
}
11+
12+
echo "OK";
13+
14+
?>
15+
--EXPECT--
16+
OK

0 commit comments

Comments
 (0)