Skip to content

Commit

Permalink
[NETBEANS-5599] PHP 8.1 Support: Never type (Part 2)
Browse files Browse the repository at this point in the history
https://issues.apache.org/jira/browse/NETBEANS-5599

RFC: https://wiki.php.net/rfc/noreturn_type

- Fix the code completion
- Add and fix unit tests for the code completion
  • Loading branch information
junichi11 committed Nov 27, 2021
1 parent ab498d4 commit 419c0ed
Show file tree
Hide file tree
Showing 48 changed files with 310 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ private static boolean isType(Token<PHPTokenId> token) {
|| id == PHPTokenId.PHP_TYPE_INT
|| id == PHPTokenId.PHP_TYPE_STRING
|| id == PHPTokenId.PHP_TYPE_VOID
|| id == PHPTokenId.PHP_TYPE_NEVER
|| id == PHPTokenId.PHP_TYPE_OBJECT
|| id == PHPTokenId.PHP_TYPE_MIXED
|| id == PHPTokenId.PHP_SELF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,10 @@ public CodeCompletionResult complete(CodeCompletionContext completionContext) {
typesForReturnTypeName.remove(Type.FALSE);
typesForReturnTypeName.remove(Type.NULL);
typesForReturnTypeName.remove(Type.VOID);
typesForReturnTypeName.remove(Type.NEVER);
} else if (context == CompletionContext.RETURN_UNION_TYPE_NAME) {
typesForReturnTypeName.remove(Type.VOID);
typesForReturnTypeName.remove(Type.NEVER);
typesForReturnTypeName.remove(Type.MIXED);
}
autoCompleteKeywords(completionResult, request, typesForReturnTypeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD string null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// PHP 8.1 Never type
// https://wiki.php.net/rfc/noreturn_type

function returnType(): never { // func
}

function invalidInParameter(never $never): never { // func
}

class TestClass {
public function returnType(): never { // class
}
public function invalidInParameter(never $never): never { // class
}
}

trait TestTrait {
public function returnType(): never { // trait
}
public function invalidInParameter(never $never): never { // trait
}
}

interface TestInterface {
public function returnType(): never; // interface
public function invalidInParameter(never $never): never; // interface
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Code completion result for source line:
public function returnType(): |never { // class
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
CLASS TestClass [PUBLIC] neverReturnType.php
CLASS TestInterface [PUBLIC] neverReturnType.php
------------------------------------
KEYWORD array null
KEYWORD bool null
KEYWORD callable null
KEYWORD false null
KEYWORD float null
KEYWORD int null
KEYWORD iterable null
KEYWORD mixed null
KEYWORD never null
KEYWORD null null
KEYWORD object null
KEYWORD parent null
KEYWORD self null
KEYWORD static null
KEYWORD string null
KEYWORD void null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
public function returnType(): neve|r { // class
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
KEYWORD never null
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Code completion result for source line:
public function invalidInParameter(ne|ver $never): never { // class
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
Loading

0 comments on commit 419c0ed

Please sign in to comment.