Skip to content

Commit 04a31ab

Browse files
committed
Switch to more explicit <- returns, allow omitting <- for terminating blocks
1 parent 3ccbc43 commit 04a31ab

23 files changed

+641
-583
lines changed

Zend/Optimizer/dce.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ static inline bool may_have_side_effects(
154154
case ZEND_INCLUDE_OR_EVAL:
155155
case ZEND_THROW:
156156
case ZEND_MATCH_ERROR:
157+
case ZEND_MATCH_BLOCK_NO_VALUE_ERROR:
157158
case ZEND_EXT_STMT:
158159
case ZEND_EXT_FCALL_BEGIN:
159160
case ZEND_EXT_FCALL_END:

Zend/tests/match/block_arg_return.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Match expression block must not use return
33
--FILE--
44
<?php
55
foo(match (1) {
6-
1 => { return; null }
6+
1 => { return; }
77
});
88
?>
99
--EXPECTF--

Zend/tests/match/block_basic.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ function bar() {
1212

1313
function test($value) {
1414
var_dump(match ($value) {
15-
1 => { 1 },
16-
2 => { $x = 2; $x },
15+
1 => { <- 1; },
16+
2 => {
17+
$x = 2;
18+
<- $x;
19+
},
1720
3 => {
1821
foo();
19-
bar()
22+
<- bar();
2023
},
2124
});
2225
}

Zend/tests/match/block_expr_break_escape.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Match expression block must not use break
33
--FILE--
44
<?php
55
var_dump(match ($value) {
6-
1 => { break; [] },
6+
1 => { break; },
77
});
88
?>
99
--EXPECTF--

Zend/tests/match/block_expr_break_no_escape.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var_dump(match (1) {
88
echo $value, "\n";
99
break;
1010
}
11-
42
11+
<- 42;
1212
},
1313
});
1414
?>

Zend/tests/match/block_expr_goto_escape.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Match expression block must not use goto
55
var_dump(match (1) {
66
1 => {
77
goto after;
8-
42
98
},
109
});
1110
after:

Zend/tests/match/block_expr_goto_into.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ goto in;
66
var_dump(match (1) {
77
1 => {
88
in:
9-
42
9+
<- 42;
1010
},
1111
});
1212
?>

Zend/tests/match/block_expr_no_result.phpt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
Match expression block must return a value
33
--FILE--
44
<?php
5-
var_dump(match (1) {
6-
1 => {
7-
echo "Not returning anything\n";
8-
},
9-
});
5+
function test() {
6+
var_dump(match (1) {
7+
1 => {
8+
echo "Not returning anything\n";
9+
},
10+
});
11+
}
12+
try {
13+
test();
14+
} catch (Error $e) {
15+
echo $e->getMessage(), "\n";
16+
}
1017
?>
11-
--EXPECTF--
12-
Fatal error: Blocks of match expression with used result must return a value. Did you mean to omit the last semicolon? in %s on line %d
18+
--EXPECT--
19+
Not returning anything
20+
Match expected a value from block but none was returned

Zend/tests/match/block_expr_return.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Match expression block must not use return
33
--FILE--
44
<?php
55
var_dump(match ($value) {
6-
1 => { return; [] },
6+
1 => { return; },
77
});
88
?>
99
--EXPECTF--

Zend/tests/match/block_expr_throw.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Throwing match expression block must clean up live-vars
55

66
function throw_($value) {
77
var_dump([new \stdClass] + match ($value) {
8-
1 => { throw new Exception('Exception with live var'); [] },
8+
1 => { throw new Exception('Exception with live var'); },
99
});
1010
}
1111

0 commit comments

Comments
 (0)