File tree Expand file tree Collapse file tree 4 files changed +20
-8
lines changed Expand file tree Collapse file tree 4 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ var_dump('' is string);
1010var_dump('' is int);
1111var_dump('' is bool);
1212var_dump('' is object);
13+ var_dump('' is ?string);
14+ var_dump(null is ?string);
15+ var_dump('' is ?object);
1316
1417?>
1518--EXPECT--
1619bool(true)
1720bool(false)
1821bool(false)
1922bool(false)
23+ bool(true)
24+ bool(true)
25+ bool(false)
Original file line number Diff line number Diff line change @@ -11,6 +11,13 @@ class Foo {
1111 const FOO = 'foo ' ;
1212}
1313
14+ var_dump (match (null ) {
15+ is false => wrong (),
16+ is 0 => wrong (),
17+ is [] => wrong (),
18+ is null => 'Literal pattern with null ' ,
19+ });
20+
1421var_dump (match (true ) {
1522 is false => wrong (),
1623 is true => 'Literal pattern with bool ' ,
@@ -57,20 +64,14 @@ var_dump(match (15) {
5764 is 20 .. < 30 => wrong (),
5865});
5966
60- // var_dump(match (true) {
61- // false if false => wrong(),
62- // false if true => wrong(),
63- // true if false => wrong(),
64- // true if true => 'Guard',
65- // });
66-
6767// var_dump(match ('foo') {
6868// is 'bar' => wrong(),
6969// is Foo::FOO => 'Class constant literal',
7070// });
7171
7272?>
7373--EXPECT--
74+ string(25) "Literal pattern with null"
7475string(25) "Literal pattern with bool"
7576string(24) "Literal pattern with int"
7677string(27) "Literal pattern with string"
Original file line number Diff line number Diff line change @@ -6124,7 +6124,12 @@ static void zend_compile_type_pattern(zend_ast **ast_ptr)
61246124{
61256125 zend_ast * type_pattern_ast = * ast_ptr ;
61266126 zend_ast * type_ast = type_pattern_ast -> child [0 ];
6127+ bool nullable = type_ast -> attr & ZEND_TYPE_NULLABLE ;
6128+ type_ast -> attr &= ~ZEND_TYPE_NULLABLE ;
61276129 zend_type type = zend_compile_single_typename (type_ast );
6130+ if (nullable ) {
6131+ ZEND_TYPE_FULL_MASK (type ) |= MAY_BE_NULL ;
6132+ }
61286133 uint32_t type_mask = ZEND_TYPE_PURE_MASK (type );
61296134
61306135 // FIXME: Make sure the type mask actually fits
Original file line number Diff line number Diff line change @@ -1302,7 +1302,7 @@ compound_pattern:
13021302
13031303type_pattern :
13041304 type_without_static { $$ = zend_ast_create(ZEND_AST_TYPE_PATTERN, $1 ); }
1305- | ' ?' type_without_static { $$ = zend_ast_create(ZEND_AST_TYPE_PATTERN, $2 ); $$ ->attr |= ZEND_TYPE_NULLABLE; }
1305+ | ' ?' type_without_static { $$ = zend_ast_create(ZEND_AST_TYPE_PATTERN, $2 ); $2 ->attr |= ZEND_TYPE_NULLABLE; }
13061306;
13071307
13081308scalar_pattern :
You can’t perform that action at this time.
0 commit comments