-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix Incorrect Type Inference when Declaring Macros #3174
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
Conversation
29ac070
to
44583f3
Compare
I had to alter the I needed to swap:
for
This is because this I think to resolve this properly (as in, without needing to ignore an error) - the logic that handles "whether we're in a static context" (see below) would need to rejigged. I think this would be out of the scope of this PR? private static function loadMixinTrait(string $trait): void
{
$context = eval(self::getAnonymousClassCodeForTrait($trait));
$className = \get_class($context);
$baseClass = static::class;
foreach (self::getMixableMethods($context) as $name) {
$closureBase = Closure::fromCallable([$context, $name]);
static::macro($name, function (...$parameters) use ($closureBase, $className, $baseClass) {
// This is the "whether we're in a static context" I'm referring to
$downContext = isset($this) ? ($this) : new $baseClass();
$context = isset($this) ? $this->cast($className) : new $className();
// ... I only added
However I've left them out to keep the PR as slim as possible (feels slight pointless after writing this wall of text 😅) - happy to be directed otherwise. Thanks! |
Failures all look unrelated to this PR? |
Only the error ignore is to be removed from the phpstan config, the rest is fine. |
I think the Laravel test failures are due to also unrelated? see this. Edit: sorry I misread that - I'll look into the PHPStan error. |
…croTest::diffInYears()
I've resolved that PHPStan issue. It occurs (for me) on I can't immediately see how it could be related to my change? |
Hey, resolves #3173 using param-closure-this.