Skip to content
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

Imported types cannot be used as array keys in 5.18.0 #10496

Closed
TJ09 opened this issue Dec 17, 2023 · 3 comments · Fixed by #10508
Closed

Imported types cannot be used as array keys in 5.18.0 #10496

TJ09 opened this issue Dec 17, 2023 · 3 comments · Fixed by #10508

Comments

@TJ09
Copy link

TJ09 commented Dec 17, 2023

<?php

/**
 * @psalm-type ArrayKeyType array-key
 */
class Bar {}

/**
 * @psalm-import-type ArrayKeyType from Bar
 * @psalm-type UsesArrayKeyType array<ArrayKeyType, bool>
 */
class Foo {}

Link: https://psalm.dev/r/72f05104ae

Note that there are no errors in psalm.dev at the time of writing (but it's also running a week-old commit: a75d26a).

Psalm 5.17 reports no errors, while Psalm 5.18 reports:

ERROR: InvalidDocblock - lib/Foo.php:12:1 - Invalid array key type ArrayKeyType (see https://psalm.dev/008)
/**
 * @psalm-import-type ArrayKeyType from Bar
 * @psalm-type UsesArrayKeyType array<ArrayKeyType, bool>
 */
class Foo {}

As far as I can tell ArrayKeyType as array-key is definitely an okay array key type.

Copy link

I found these snippets:

https://psalm.dev/r/72f05104ae
<?php

/**
 * @psalm-type ArrayKeyType array-key
 */
class Bar {}

/**
 * @psalm-import-type ArrayKeyType from Bar
 * @psalm-type UsesArrayKeyType array<ArrayKeyType, bool>
 */
class Foo {}
Psalm output (using commit a75d26a):

No issues!

@ging-dev
Copy link
Contributor

ging-dev commented Dec 17, 2023

Rated 82ff582
cc @kkmuffme

@kkmuffme
Copy link
Contributor

Yeah, I expected this, since I don't have a complete list of all string-ish types of psalm. This is a good first issue to add the additional types to the conditions there - validate that they are any of the allowed array-key types though

ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 19, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 19, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 19, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 20, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 20, 2023
orklah added a commit that referenced this issue Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants