fix: fix parsing by_ref parameters (#179)

Signed-off-by: azjezz <azjezz@protonmail.com>
This commit is contained in:
Saif Eddin Gmati 2022-12-08 18:07:03 +01:00 committed by GitHub
parent 8af0c1e3a1
commit 4d0cd75fa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33251 additions and 6 deletions

View File

@ -25,7 +25,10 @@ pub fn data_type(state: &mut State) -> ParseResult<Type> {
}
if state.current.kind == TokenKind::Ampersand
&& !matches!(state.peek.kind, TokenKind::Variable(_))
&& !matches!(
state.peek.kind,
TokenKind::Variable(_) | TokenKind::Ellipsis | TokenKind::Ampersand
)
{
return instersection(state, ty, false);
}
@ -52,7 +55,10 @@ pub fn optional_data_type(state: &mut State) -> ParseResult<Option<Type>> {
}
if state.current.kind == TokenKind::Ampersand
&& !matches!(state.peek.kind, TokenKind::Variable(_))
&& !matches!(
state.peek.kind,
TokenKind::Variable(_) | TokenKind::Ellipsis | TokenKind::Ampersand
)
{
return instersection(state, ty, false).map(Some);
}
@ -328,7 +334,10 @@ fn instersection(state: &mut State, other: Type, within_dnf: bool) -> ParseResul
types.push(ty);
if state.current.kind == TokenKind::Ampersand
&& !matches!(state.peek.kind, TokenKind::Variable(_))
&& !matches!(
state.peek.kind,
TokenKind::Variable(_) | TokenKind::Ellipsis | TokenKind::Ampersand
)
{
state.next();
} else {

View File

@ -41,7 +41,6 @@ pub fn function_parameter_list(state: &mut State) -> Result<FunctionParameterLis
if state.current.kind == TokenKind::Ellipsis {
state.next();
variadic = true;
}

16222
tests/fixtures/0275/ast.txt vendored Normal file

File diff suppressed because it is too large Load Diff

104
tests/fixtures/0275/code.php vendored Normal file
View File

@ -0,0 +1,104 @@
<?php
static fn (Foo &...$s): Bar => Bar::from($s);
static fn (Foo ...$s): Bar => Bar::from($s);
static fn (Foo &$s): Bar => Bar::from($s);
static fn (Foo $s): Bar => Bar::from($s);
static function (Foo &...$s): Bar { return Bar::from($s); };
static function (Foo ...$s): Bar { return Bar::from($s); };
static function (Foo &$s): Bar { return Bar::from($s); };
static function (Foo $s): Bar { return Bar::from($s); };
static fn (Foo&Bar&Baz &...$s): Bar => Bar::from($s);
static fn (Foo&Bar&Baz ...$s): Bar => Bar::from($s);
static fn (Foo&Bar&Baz &$s): Bar => Bar::from($s);
static fn (Foo&Bar&Baz $s): Bar => Bar::from($s);
static function (Foo&Bar&Baz &...$s): Bar { return Bar::from($s); };
static function (Foo&Bar&Baz ...$s): Bar { return Bar::from($s); };
static function (Foo&Bar&Baz &$s): Bar { return Bar::from($s); };
static function (Foo&Bar&Baz $s): Bar { return Bar::from($s); };
static fn (Foo|Bar|Baz &...$s): Bar => Bar::from($s);
static fn (Foo|Bar|Baz ...$s): Bar => Bar::from($s);
static fn (Foo|Bar|Baz &$s): Bar => Bar::from($s);
static fn (Foo|Bar|Baz $s): Bar => Bar::from($s);
static function (Foo|Bar|Baz &...$s): Bar { return Bar::from($s); };
static function (Foo|Bar|Baz ...$s): Bar { return Bar::from($s); };
static function (Foo|Bar|Baz &$s): Bar { return Bar::from($s); };
static function (Foo|Bar|Baz $s): Bar { return Bar::from($s); };
static fn (Foo|(Bar&Baz) &...$s): Bar => Bar::from($s);
static fn (Foo|(Bar&Baz) ...$s): Bar => Bar::from($s);
static fn (Foo|(Bar&Baz) &$s): Bar => Bar::from($s);
static fn (Foo|(Bar&Baz) $s): Bar => Bar::from($s);
static function (Foo|(Bar&Baz) &...$s): Bar { return Bar::from($s); };
static function (Foo|(Bar&Baz) ...$s): Bar { return Bar::from($s); };
static function (Foo|(Bar&Baz) &$s): Bar { return Bar::from($s); };
static function (Foo|(Bar&Baz) $s): Bar { return Bar::from($s); };
static fn (Foo&(Bar|Baz) &...$s): Bar => Bar::from($s);
static fn (Foo&(Bar|Baz) ...$s): Bar => Bar::from($s);
static fn (Foo&(Bar|Baz) &$s): Bar => Bar::from($s);
static fn (Foo&(Bar|Baz) $s): Bar => Bar::from($s);
static function (Foo&(Bar|Baz) &...$s): Bar { return Bar::from($s); };
static function (Foo&(Bar|Baz) ...$s): Bar { return Bar::from($s); };
static function (Foo&(Bar|Baz) &$s): Bar { return Bar::from($s); };
static function (Foo&(Bar|Baz) $s): Bar { return Bar::from($s); };
fn (Foo &...$s): Bar => Bar::from($s);
fn (Foo ...$s): Bar => Bar::from($s);
fn (Foo &$s): Bar => Bar::from($s);
fn (Foo $s): Bar => Bar::from($s);
function (Foo &...$s): Bar { return Bar::from($s); };
function (Foo ...$s): Bar { return Bar::from($s); };
function (Foo &$s): Bar { return Bar::from($s); };
function (Foo $s): Bar { return Bar::from($s); };
fn (Foo&Bar&Baz &...$s): Bar => Bar::from($s);
fn (Foo&Bar&Baz ...$s): Bar => Bar::from($s);
fn (Foo&Bar&Baz &$s): Bar => Bar::from($s);
fn (Foo&Bar&Baz $s): Bar => Bar::from($s);
function (Foo&Bar&Baz &...$s): Bar { return Bar::from($s); };
function (Foo&Bar&Baz ...$s): Bar { return Bar::from($s); };
function (Foo&Bar&Baz &$s): Bar { return Bar::from($s); };
function (Foo&Bar&Baz $s): Bar { return Bar::from($s); };
fn (Foo|Bar|Baz &...$s): Bar => Bar::from($s);
fn (Foo|Bar|Baz ...$s): Bar => Bar::from($s);
fn (Foo|Bar|Baz &$s): Bar => Bar::from($s);
fn (Foo|Bar|Baz $s): Bar => Bar::from($s);
function (Foo|Bar|Baz &...$s): Bar { return Bar::from($s); };
function (Foo|Bar|Baz ...$s): Bar { return Bar::from($s); };
function (Foo|Bar|Baz &$s): Bar { return Bar::from($s); };
function (Foo|Bar|Baz $s): Bar { return Bar::from($s); };
fn (Foo|(Bar&Baz) &...$s): Bar => Bar::from($s);
fn (Foo|(Bar&Baz) ...$s): Bar => Bar::from($s);
fn (Foo|(Bar&Baz) &$s): Bar => Bar::from($s);
fn (Foo|(Bar&Baz) $s): Bar => Bar::from($s);
function (Foo|(Bar&Baz) &...$s): Bar { return Bar::from($s); };
function (Foo|(Bar&Baz) ...$s): Bar { return Bar::from($s); };
function (Foo|(Bar&Baz) &$s): Bar { return Bar::from($s); };
function (Foo|(Bar&Baz) $s): Bar { return Bar::from($s); };
fn (Foo&(Bar|Baz) &...$s): Bar => Bar::from($s);
fn (Foo&(Bar|Baz) ...$s): Bar => Bar::from($s);
fn (Foo&(Bar|Baz) &$s): Bar => Bar::from($s);
fn (Foo&(Bar|Baz) $s): Bar => Bar::from($s);
function (Foo&(Bar|Baz) &...$s): Bar { return Bar::from($s); };
function (Foo&(Bar|Baz) ...$s): Bar { return Bar::from($s); };
function (Foo&(Bar|Baz) &$s): Bar { return Bar::from($s); };
function (Foo&(Bar|Baz) $s): Bar { return Bar::from($s); };
function foo(Foo &...$s): Bar { return Bar::from($s); }
function foo(Foo ...$s): Bar { return Bar::from($s); }
function foo(Foo &$s): Bar { return Bar::from($s); }
function foo(Foo $s): Bar { return Bar::from($s); }
function foo(Foo&Bar&Baz &...$s): Bar { return Bar::from($s); }
function foo(Foo&Bar&Baz ...$s): Bar { return Bar::from($s); }
function foo(Foo&Bar&Baz &$s): Bar { return Bar::from($s); }
function foo(Foo&Bar&Baz $s): Bar { return Bar::from($s); }
function foo(Foo|Bar|Baz &...$s): Bar { return Bar::from($s); }
function foo(Foo|Bar|Baz ...$s): Bar { return Bar::from($s); }
function foo(Foo|Bar|Baz &$s): Bar { return Bar::from($s); }
function foo(Foo|Bar|Baz $s): Bar { return Bar::from($s); }
function foo(Foo|(Bar&Baz) &...$s): Bar { return Bar::from($s); }
function foo(Foo|(Bar&Baz) ...$s): Bar { return Bar::from($s); }
function foo(Foo|(Bar&Baz) &$s): Bar { return Bar::from($s); }
function foo(Foo|(Bar&Baz) $s): Bar { return Bar::from($s); }
function foo(Foo&(Bar|Baz) &...$s): Bar { return Bar::from($s); }
function foo(Foo&(Bar|Baz) ...$s): Bar { return Bar::from($s); }
function foo(Foo&(Bar|Baz) &$s): Bar { return Bar::from($s); }
function foo(Foo&(Bar|Baz) $s): Bar { return Bar::from($s); }

16911
tests/fixtures/0275/tokens.txt vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -80,8 +80,8 @@ fn third_party_6_spiral_framework() {
&["src", "tests"],
&[
// file contains syntax error used for testing.
"/src/Core/tests/Fixtures/CorruptedClass.php",
"/src/Tokenizer/tests/Classes/BrokenClass.php",
"src/Core/tests/Fixtures/CorruptedClass.php",
"src/Tokenizer/tests/Classes/BrokenClass.php",
],
);
}