Skip to content
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
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function __construct() {
[TokenKind::ArrayKeyword, TokenKind::CallableKeyword, TokenKind::BoolReservedWord,
TokenKind::FloatReservedWord, TokenKind::IntReservedWord, TokenKind::StringReservedWord,
TokenKind::ObjectReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord]; // TODO update spec
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord], $this->parameterTypeDeclarationTokens);
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord, TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/parser/staticReturnType1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
class A {
public function f() : static {
return $this;
}
}
1 change: 1 addition & 0 deletions tests/cases/parser/staticReturnType1.php.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
122 changes: 122 additions & 0 deletions tests/cases/parser/staticReturnType1.php.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"SourceFileNode": {
"statementList": [
{
"InlineHtml": {
"scriptSectionEndTag": null,
"text": null,
"scriptSectionStartTag": {
"kind": "ScriptSectionStartTag",
"textLength": 6
}
}
},
{
"ClassDeclaration": {
"abstractOrFinalModifier": null,
"classKeyword": {
"kind": "ClassKeyword",
"textLength": 5
},
"name": {
"kind": "Name",
"textLength": 1
},
"classBaseClause": null,
"classInterfaceClause": null,
"classMembers": {
"ClassMembersNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"classMemberDeclarations": [
{
"MethodDeclaration": {
"modifiers": [
{
"kind": "PublicKeyword",
"textLength": 6
}
],
"functionKeyword": {
"kind": "FunctionKeyword",
"textLength": 8
},
"byRefToken": null,
"name": {
"kind": "Name",
"textLength": 1
},
"openParen": {
"kind": "OpenParenToken",
"textLength": 1
},
"parameters": null,
"closeParen": {
"kind": "CloseParenToken",
"textLength": 1
},
"colonToken": {
"kind": "ColonToken",
"textLength": 1
},
"questionToken": null,
"returnType": {
"kind": "StaticKeyword",
"textLength": 6
},
"otherReturnTypes": null,
"compoundStatementOrSemicolon": {
"CompoundStatementNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"statements": [
{
"ReturnStatement": {
"returnKeyword": {
"kind": "ReturnKeyword",
"textLength": 6
},
"expression": {
"Variable": {
"dollar": null,
"name": {
"kind": "VariableName",
"textLength": 5
}
}
},
"semicolon": {
"kind": "SemicolonToken",
"textLength": 1
}
}
}
],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
}
}
],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
}
}
],
"endOfFileToken": {
"kind": "EndOfFileToken",
"textLength": 0
}
}
}
6 changes: 6 additions & 0 deletions tests/cases/parser/staticReturnType2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
class X {
// Static is forbidden in param types
public function test(static $x) {
}
}
32 changes: 32 additions & 0 deletions tests/cases/parser/staticReturnType2.php.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"kind": 0,
"message": "')' expected.",
"start": 83,
"length": 0
},
{
"kind": 0,
"message": "'{' expected.",
"start": 83,
"length": 0
},
{
"kind": 0,
"message": "';' expected.",
"start": 92,
"length": 0
},
{
"kind": 0,
"message": "Unexpected ')'",
"start": 92,
"length": 1
},
{
"kind": 0,
"message": "'}' expected.",
"start": 103,
"length": 0
}
]
145 changes: 145 additions & 0 deletions tests/cases/parser/staticReturnType2.php.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"SourceFileNode": {
"statementList": [
{
"InlineHtml": {
"scriptSectionEndTag": null,
"text": null,
"scriptSectionStartTag": {
"kind": "ScriptSectionStartTag",
"textLength": 6
}
}
},
{
"ClassDeclaration": {
"abstractOrFinalModifier": null,
"classKeyword": {
"kind": "ClassKeyword",
"textLength": 5
},
"name": {
"kind": "Name",
"textLength": 1
},
"classBaseClause": null,
"classInterfaceClause": null,
"classMembers": {
"ClassMembersNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"classMemberDeclarations": [
{
"MethodDeclaration": {
"modifiers": [
{
"kind": "PublicKeyword",
"textLength": 6
}
],
"functionKeyword": {
"kind": "FunctionKeyword",
"textLength": 8
},
"byRefToken": null,
"name": {
"kind": "Name",
"textLength": 4
},
"openParen": {
"kind": "OpenParenToken",
"textLength": 1
},
"parameters": null,
"closeParen": {
"error": "MissingToken",
"kind": "CloseParenToken",
"textLength": 0
},
"colonToken": null,
"questionToken": null,
"returnType": null,
"otherReturnTypes": null,
"compoundStatementOrSemicolon": {
"CompoundStatementNode": {
"openBrace": {
"error": "MissingToken",
"kind": "OpenBraceToken",
"textLength": 0
},
"statements": [
{
"FunctionStaticDeclaration": {
"staticKeyword": {
"kind": "StaticKeyword",
"textLength": 6
},
"staticVariableNameList": {
"StaticVariableNameList": {
"children": [
{
"StaticVariableDeclaration": {
"variableName": {
"kind": "VariableName",
"textLength": 2
},
"equalsToken": null,
"assignment": null
}
}
]
}
},
"semicolon": {
"error": "MissingToken",
"kind": "SemicolonToken",
"textLength": 0
}
}
},
{
"error": "SkippedToken",
"kind": "CloseParenToken",
"textLength": 1
},
{
"CompoundStatementNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"statements": [],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
}
}
],
"closeBrace": {
"error": "MissingToken",
"kind": "CloseBraceToken",
"textLength": 0
}
}
}
}
}
],
"endOfFileToken": {
"kind": "EndOfFileToken",
"textLength": 0
}
}
}