Skip to content

Support php 'never' type, change parsing of 'void' #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public function __construct() {
[TokenKind::ArrayKeyword, TokenKind::CallableKeyword, TokenKind::BoolReservedWord,
TokenKind::FloatReservedWord, TokenKind::IntReservedWord, TokenKind::StringReservedWord,
TokenKind::ObjectReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord,
TokenKind::TrueReservedWord,
TokenKind::IterableReservedWord, TokenKind::MixedReservedWord]; // TODO update spec
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord, TokenKind::TrueReservedWord, TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
TokenKind::TrueReservedWord, TokenKind::IterableReservedWord, TokenKind::MixedReservedWord,
TokenKind::VoidReservedWord, TokenKind::NeverReservedWord]; // TODO update spec
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/TokenKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class TokenKind {
const NullReservedWord = 322;
const MixedReservedWord = 340;
const IterableReservedWord = 170;
const NeverReservedWord = 341;

const ScriptSectionStartTag = 323;
const ScriptSectionEndTag = 324;
Expand Down
1 change: 1 addition & 0 deletions src/TokenStringMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TokenStringMaps {
"void" => TokenKind::VoidReservedWord,
"iterable" => TokenKind::IterableReservedWord,
"mixed" => TokenKind::MixedReservedWord,
"never" => TokenKind::NeverReservedWord,
];

const OPERATORS_AND_PUNCTUATORS = [
Expand Down
2 changes: 2 additions & 0 deletions tests/cases/parser/neverReturnType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
function example() : never {}
1 change: 1 addition & 0 deletions tests/cases/parser/neverReturnType.php.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
71 changes: 71 additions & 0 deletions tests/cases/parser/neverReturnType.php.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"SourceFileNode": {
"statementList": [
{
"InlineHtml": {
"scriptSectionEndTag": null,
"text": null,
"scriptSectionStartTag": {
"kind": "ScriptSectionStartTag",
"textLength": 6
}
}
},
{
"FunctionDeclaration": {
"attributes": null,
"functionKeyword": {
"kind": "FunctionKeyword",
"textLength": 8
},
"byRefToken": null,
"name": {
"kind": "Name",
"textLength": 7
},
"openParen": {
"kind": "OpenParenToken",
"textLength": 1
},
"parameters": null,
"closeParen": {
"kind": "CloseParenToken",
"textLength": 1
},
"colonToken": {
"kind": "ColonToken",
"textLength": 1
},
"questionToken": null,
"returnTypeList": {
"QualifiedNameList": {
"children": [
{
"kind": "NeverReservedWord",
"textLength": 5
}
]
}
},
"compoundStatementOrSemicolon": {
"CompoundStatementNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"statements": [],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
}
}
],
"endOfFileToken": {
"kind": "EndOfFileToken",
"textLength": 0
}
}
}
3 changes: 3 additions & 0 deletions tests/cases/parser/parameterTypes1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
// These are fatal compile errors, not parse errors
function u(never $g, void $u) {}
1 change: 1 addition & 0 deletions tests/cases/parser/parameterTypes1.php.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
120 changes: 120 additions & 0 deletions tests/cases/parser/parameterTypes1.php.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"SourceFileNode": {
"statementList": [
{
"InlineHtml": {
"scriptSectionEndTag": null,
"text": null,
"scriptSectionStartTag": {
"kind": "ScriptSectionStartTag",
"textLength": 6
}
}
},
{
"FunctionDeclaration": {
"attributes": null,
"functionKeyword": {
"kind": "FunctionKeyword",
"textLength": 8
},
"byRefToken": null,
"name": {
"kind": "Name",
"textLength": 1
},
"openParen": {
"kind": "OpenParenToken",
"textLength": 1
},
"parameters": {
"ParameterDeclarationList": {
"children": [
{
"Parameter": {
"attributes": null,
"visibilityToken": null,
"modifiers": null,
"questionToken": null,
"typeDeclarationList": {
"QualifiedNameList": {
"children": [
{
"kind": "NeverReservedWord",
"textLength": 5
}
]
}
},
"byRefToken": null,
"dotDotDotToken": null,
"variableName": {
"kind": "VariableName",
"textLength": 2
},
"equalsToken": null,
"default": null
}
},
{
"kind": "CommaToken",
"textLength": 1
},
{
"Parameter": {
"attributes": null,
"visibilityToken": null,
"modifiers": null,
"questionToken": null,
"typeDeclarationList": {
"QualifiedNameList": {
"children": [
{
"kind": "VoidReservedWord",
"textLength": 4
}
]
}
},
"byRefToken": null,
"dotDotDotToken": null,
"variableName": {
"kind": "VariableName",
"textLength": 2
},
"equalsToken": null,
"default": null
}
}
]
}
},
"closeParen": {
"kind": "CloseParenToken",
"textLength": 1
},
"colonToken": null,
"questionToken": null,
"returnTypeList": null,
"compoundStatementOrSemicolon": {
"CompoundStatementNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"statements": [],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
}
}
],
"endOfFileToken": {
"kind": "EndOfFileToken",
"textLength": 0
}
}
}