Skip to content
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

Class PHPDoc not parsed when there's an attribute above it #4633

Open
oprypkhantc opened this issue Mar 1, 2021 · 9 comments
Open

Class PHPDoc not parsed when there's an attribute above it #4633

oprypkhantc opened this issue Mar 1, 2021 · 9 comments
Labels

Comments

@oprypkhantc
Copy link

Bug report

See the title. Moving the attribute below the PHPDoc fixes the problem and that's the usual way I would do it, but is strange either way.

Code snippet that reproduces the problem

https://phpstan.org/r/e933d057-a3d6-49b3-86c4-8b8be4090522

Expected output

Parse the PHPDoc correctly, as if the attribute was below it.

@ondrejmirtes
Copy link
Member

Reported upstream: nikic/PHP-Parser#762

@ondrejmirtes
Copy link
Member

Don't hol your breath for this being solved, see: nikic/PHP-Parser#762 (comment)

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
 15: Property ClassStub::$var has unknown class T as its type.
 
-PHP 7.1 – 7.4 (1 error)
+PHP 7.1 – 7.4 (4 errors)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+ 3: Attribute class Attribute does not exist.
+15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
Full report

PHP 8.0 (2 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid typehint type T.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.1 – 7.4 (4 errors)

Line Error
3 Attribute class Attribute does not exist.
15 Parameter $var of method ClassStub::__construct() has invalid typehint type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 7.1 – 7.4 (1 error)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+-1: Internal error: Property $var was not found in reflection of class ClassStub.
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Full report

PHP 8.0 (2 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid typehint type T.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.1 – 7.4 (1 error)

Line Error
-1 Internal error: Property $var was not found in reflection of class ClassStub.Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 (2 errors)
 ==========
 
-15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
 15: Property ClassStub::$var has unknown class T as its type.
 
-PHP 7.1 – 7.4 (1 error)
+PHP 7.1 – 7.4 (4 errors)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+ 3: Attribute class Attribute does not exist.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
Full report

PHP 8.0 (2 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.1 – 7.4 (4 errors)

Line Error
3 Attribute class Attribute does not exist.
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (2 errors)
+PHP 8.0 (4 errors)
 ==========
 
-15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
+ 3: Class Attribute is not an Attribute class.
+ 6: Class AttributeStub is not an Attribute class.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
 15: Property ClassStub::$var has unknown class T as its type.
 
-PHP 7.1 – 7.4 (1 error)
+PHP 7.1 – 7.4 (5 errors)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+ 3: Attribute class Attribute does not exist.
+ 6: Class AttributeStub is not an Attribute class.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
Full report

PHP 8.0 (4 errors)

Line Error
3 Class Attribute is not an Attribute class.
6 Class AttributeStub is not an Attribute class.
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.1 – 7.4 (5 errors)

Line Error
3 Attribute class Attribute does not exist.
6 Class AttributeStub is not an Attribute class.
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 (2 errors)
 ==========
 
-15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
 15: Property ClassStub::$var has unknown class T as its type.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
 
-PHP 7.1 – 7.4 (1 error)
+PHP 7.1 – 7.4 (4 errors)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+ 3: Attribute class Attribute does not exist.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
Full report

PHP 8.0 (2 errors)

Line Error
15 Property ClassStub::$var has unknown class T as its type.
15 Parameter $var of method ClassStub::__construct() has invalid type T.

PHP 7.1 – 7.4 (4 errors)

Line Error
3 Attribute class Attribute does not exist.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.
15 Parameter $var of method ClassStub::__construct() has invalid type T.

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 (2 errors)
 ==========
 
-15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
 15: Property ClassStub::$var has unknown class T as its type.
 
-PHP 7.1 – 7.4 (1 error)
+PHP 7.4 (3 errors)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
+
+PHP 7.3 (4 errors)
+==========
+
+ 3: Attribute class Attribute does not exist.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
+
+PHP 7.1 – 7.2 (3 errors)
+==========
+
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
Full report

PHP 8.0 (2 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.4 (3 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.3 (4 errors)

Line Error
3 Attribute class Attribute does not exist.
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.1 – 7.2 (3 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

@phpstan-bot
Copy link
Contributor

@oprypkhantc After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 (2 errors)
 ==========
 
-15: Parameter $var of method ClassStub::__construct() has invalid typehint type T.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
 15: Property ClassStub::$var has unknown class T as its type.
 
-PHP 7.1 – 7.4 (1 error)
+PHP 7.1 – 7.4 (3 errors)
 ==========
 
-15: Promoted properties are supported only on PHP 8.0 and later.
+15: Parameter $var of method ClassStub::__construct() has invalid type T.
+15: Promoted properties are supported only on PHP 8.0 and later.
+15: Property ClassStub::$var has unknown class T as its type.
Full report

PHP 8.0 (2 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Property ClassStub::$var has unknown class T as its type.

PHP 7.1 – 7.4 (3 errors)

Line Error
15 Parameter $var of method ClassStub::__construct() has invalid type T.
15 Promoted properties are supported only on PHP 8.0 and later.
15 Property ClassStub::$var has unknown class T as its type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants