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

Type lost in foreach variable #3063

Open
MauroVinicius opened this issue Sep 16, 2024 · 1 comment
Open

Type lost in foreach variable #3063

MauroVinicius opened this issue Sep 16, 2024 · 1 comment
Labels

Comments

@MauroVinicius
Copy link

Describe the bug
When using foreach the "go to definion" of type variable's value is lost

To Reproduce

class Pikachu {

}

$pokemons = [new Pikachu];


foreach ($pokemons as $pokemon) {
	# code...
}

Expected behavior
Go to definiton works normally

Screenshots
image
image

Platform and version
Windows 11, Intelephense v1.12.6

@bmewburn bmewburn added the bug label Sep 16, 2024
@UndefinedOffset
Copy link

UndefinedOffset commented Sep 23, 2024

I've noticed something similar, so I didn't want to create another issue since it's perhaps related. In this case we have methods that return a return type that results in an integer keyed array of another object (return type defined as \SilverStripe\ORM\DataList|\****\Model\ResilienceTool\ResilienceQuestion[]).

This results in intelephense showing:
issue-1

Which should be accurate, both shuffle() and limit() have a return type of static<T>:
issue-2

However in the foreach loop it's seeing int as the type of the $question variable:
issue-3

If I add a variable to place the key in foreach ($questions as $key => $question) the $key is interpreted by intelephense as a type mixed and question is still int.

Edit: In looking again worth noting that hovering $questions results in a type of \SilverStripe\ORM\DataList<int>, even removing the call to limit results in the same. So in my case it appears to be getting lost earlier than the loop. However removing shuffle() and limit() still does result in the loop showing a type of int for $question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants