Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7123 from AndrolGenhald/feature/942-type-annotate…
…-class-constants Support type annotations for class consts (fixes #942).
- Loading branch information
Showing
29 changed files
with
610 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
docs/running_psalm/issues/InvalidConstantAssignmentValue.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# InvalidConstantAssignmentValue | ||
|
||
Emitted when attempting to assign a value to a class constant that cannot contain that type. | ||
|
||
```php | ||
<?php | ||
|
||
class Foo { | ||
/** @var int */ | ||
public const BAR = "bar"; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# UnresolvableConstant | ||
|
||
Emitted when Psalm cannot resolve a constant used in `key-of` or `value-of`. Note that `static::CONST` is considered | ||
unresolvable for `key-of` and `value-of`, since the literal keys and values can't be resolved due to the possibility | ||
of being overridden by child classes. | ||
|
||
```php | ||
<?php | ||
|
||
class Foo | ||
{ | ||
public const BAR = ['bar']; | ||
|
||
/** | ||
* @return value-of<self::BAT> | ||
*/ | ||
public function bar(): string | ||
{ | ||
return self::BAR[0]; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Psalm\Exception; | ||
|
||
use Exception; | ||
|
||
class UnresolvableConstantException extends Exception | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $class_name; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $const_name; | ||
|
||
public function __construct(string $class_name, string $const_name) | ||
{ | ||
$this->class_name = $class_name; | ||
$this->const_name = $const_name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.