mirror of
https://github.com/danog/parser.git
synced 2024-11-26 20:04:57 +01:00
fix: fix parsing by_ref parameters (#179)
Signed-off-by: azjezz <azjezz@protonmail.com>
This commit is contained in:
parent
8af0c1e3a1
commit
4d0cd75fa9
@ -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 {
|
||||
|
@ -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
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
104
tests/fixtures/0275/code.php
vendored
Normal 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
16911
tests/fixtures/0275/tokens.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user