-
Notifications
You must be signed in to change notification settings - Fork 551
Fix get_class return type
#4456
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
base: 2.1.x
Are you sure you want to change the base?
Changes from all commits
712635a
a8f4c64
a496efa
0fb0665
bec0a6f
f409b6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,4 +63,9 @@ public function toStrictMixedType(): TemplateStrictMixedType | |
| ); | ||
| } | ||
|
|
||
| public function getClassStringType(): Type | ||
| { | ||
| return new GenericClassStringType($this); | ||
| } | ||
|
|
||
|
Comment on lines
+66
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might also be worth testing with templates
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also added |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,11 @@ public function getObjectClassNames(): array; | |
| /** @return list<ClassReflection> */ | ||
| public function getObjectClassReflections(): array; | ||
|
|
||
| /** | ||
| * Return class-string<Foo> for object type Foo. | ||
| */ | ||
| public function getClassStringType(): Type; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to document what this is supposed to return similarly to how
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added |
||
|
|
||
| /** | ||
| * Returns the object type for a class-string or literal class name string. | ||
| * For non-class-string types, returns ErrorType. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| namespace Bug4890Php8; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| enum MyEnum | ||
| { | ||
| case CASE1; | ||
| case CASE2; | ||
|
|
||
| public function someMethod(): bool { return true; } | ||
| } | ||
|
|
||
| class HelloWorld | ||
| { | ||
| public function withEnumCase(\UnitEnum $entity): void | ||
| { | ||
| assertType('class-string<UnitEnum>', get_class($entity)); | ||
| assert(method_exists($entity, 'someMethod')); | ||
| assertType('class-string<UnitEnum&hasMethod(someMethod)>', get_class($entity)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my experience enum-case can generate a separate class of bugs, therefore I think we should have a separate test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand which test you expect since the bug was about class with
hasPropertyand an enum-case cannot have a property.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it could have a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong but since an enum is final
method_existscalls will be either always true or always false on it and the HasMethodType won't be added.I'm getting
Do you have a test in mind ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I forgot bout the base enum classes... UnitEnum.
I added the test !