-
Notifications
You must be signed in to change notification settings - Fork 653
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
Plus operator in class const not resolving type when referencing parent const #5588
Comments
I found these snippets: https://psalm.dev/r/70beb89706<?php
class A {
public const FOO = ['foo' => true];
public const BAR = self::FOO + ['bar' => true];
}
/** @psalm-trace $foo */
$foo = A::FOO;
/** @psalm-trace $bar */
$bar = A::BAR;
https://psalm.dev/r/cbc8e21d41<?php
class A {
/** @var array<string, true> */
public const ARR = [
'A' => true,
];
}
class B extends A {
/** @var array<string, true> */
public const ARR = parent::ARR + [
'B' => true,
];
}
class C extends B {
/** @var array<string, true> */
public const ARR = parent::ARR + [
'C' => true,
];
}
/** @psalm-trace $a */
$a = A::ARR;
/** @psalm-trace $b */
$b = B::ARR;
/** @psalm-trace $c */
$c = C::ARR;
https://psalm.dev/r/6b0c9ee8fc<?php
class A {
public const INT = 1;
}
class B extends A {
public const INT = parent::INT + 2;
}
class C extends B {
public const INT = parent::INT + 3;
}
/** @psalm-trace $a */
$a = A::INT;
/** @psalm-trace $b */
$b = B::INT;
/** @psalm-trace $c */
$c = C::INT;
https://psalm.dev/r/b67a63d851<?php
class A {
public const STR = 'a';
}
class B extends A {
public const STR = parent::STR . 'b';
}
class C extends B {
public const STR = parent::STR . 'c';
}
/** @psalm-trace $a */
$a = A::STR;
/** @psalm-trace $b */
$b = B::STR;
/** @psalm-trace $c */
$c = C::STR;
|
AndrolGenhald
added a commit
to AndrolGenhald/psalm
that referenced
this issue
Apr 7, 2021
Handle array plus operator (fixes vimeo#5588). Handle array spread operator. Improve string concatenation to resolve to literal instead of unknown string. I feel like it should be possible to let ConstantTypeResolver take advantage of the better type analysis in ArrayAnalyzer, ConcatAnalyzer, etc, but it would require a restructuring that's beyond me for the time being.
muglug
pushed a commit
that referenced
this issue
Apr 8, 2021
Handle array plus operator (fixes #5588). Handle array spread operator. Improve string concatenation to resolve to literal instead of unknown string. I feel like it should be possible to let ConstantTypeResolver take advantage of the better type analysis in ArrayAnalyzer, ConcatAnalyzer, etc, but it would require a restructuring that's beyond me for the time being.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Referencing self consts seem to work fine: https://psalm.dev/r/70beb89706
But referencing parent consts causes the type to become
mixed
: https://psalm.dev/r/cbc8e21d41Broken for ints too: https://psalm.dev/r/6b0c9ee8fc
Concatenation seems to work ok, though it changes the type to
string
instead of resolving the literal concatenation: https://psalm.dev/r/b67a63d851The text was updated successfully, but these errors were encountered: