-
Notifications
You must be signed in to change notification settings - Fork 504
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
test: add failing test case for bug #11857 #3599
Conversation
a450662
to
bb5ef62
Compare
Please see my commits. Can you grab the PHAR from https://github.com/phpstan/phpstan-src/actions/runs/11701663721, copy it into your vendor/phpstan/phpstan/ and test it thoroughly on Larastan and real-world projects to see if it fixes the issue? Thanks. |
Also I modified the test expectation and added one ignore, please tell me if it's still okay. |
This fixed the relation errors, but it caused errors when using a trait with methods that return |
This reverts commit 0ae429c.
7540c48
to
69f3d87
Compare
69f3d87
to
3da993b
Compare
This pull request has been marked as ready for review. |
I'm pretty confident with the changes now. |
Thank you. |
Thank you!! |
Hi @calebdw, Thank improve the generic relation to Relations! While enhancing generic relations for Relations, I encountered an issue: when a Reproduction Code: <?php
namespace Bug11857;
use function PHPStan\Testing\assertType;
abstract class Model {
/** @return BelongsTo<*, *> */
public function belongsTo(string $related): BelongsTo {
return new BelongsTo();
}
}
/**
* @template TRelatedModel of Model
* @template TDeclaringModel of Model
*/
class BelongsTo {}
class Post extends Model {
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo {
return $this->belongsTo(User::class);
}
}
final class ChildPost extends Post {
public function user(): BelongsTo {
return $this->belongsTo(User::class);
}
}
function test(ChildPost $child): void {
assertType('Bug11857\BelongsTo<Bug11857\User, Bug11857\ChildPost>', $child->user());
} Error Output: ------ ---------------------------------------------------------------
Line test.php
------ ---------------------------------------------------------------
42 Return type (Bug11857\BelongsTo<Bug11857\User, $this(Bug11857\ChildPost)>)
of method Bug11857\ChildPost::user() should be compatible with
return type (Bug11857\BelongsTo<Bug11857\User, $this(Bug11857\Post)>)
of method Bug11857\Post::user()
🪪 method.childReturnType
------ --------------------------------------------------------------- PHPStan version is 2.1.6 |
There's no reason for the child to override the parent class Post extends Model {
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo {
return $this->belongsTo(User::class);
}
}
final class ChildPost extends Post {
} However, please open new bug reports so we can better track them |
Adds a failing test for phpstan/phpstan#11857