Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow [] after generic type or array shape - closes #36 #37

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

Merged
ondrejmirtes merged 1 commit into phpstan:master from iluuu1994:issue-36
Jan 25, 2020

Conversation

Copy link
Contributor

@iluuu1994 iluuu1994 commented Jan 23, 2020

No description provided.

Copy link
Contributor Author

@JanTvrdik Can you review this too since you raised some concerns?

Copy link
Collaborator

I hate it. I want the ambiguous [] syntax to die.

The most practical mess will be probably with callable types, because callable(): string[] will now be parsed as array of callables returning string.

hrach and orklah reacted with thumbs up emoji

Copy link
Contributor Author

Lol, I'll add a test for that to be sure. I still don't see how [] are ambiguous. They're not more ambiguous than any other postfix operator. I don't like the fact that it defaults to TKey being array-key but I don't think the syntax will go anywhere soon.

Copy link
Member

ondrejmirtes commented Jan 24, 2020
edited
Loading

I don't like the fact that it defaults to TKey being array-key but I don't think the syntax will go anywhere soon.

I don't know what you're talking about, can you post an example?

The callable example is bad and should be solved in an elegant way (so that it means "callable that returns array<string>"). But it's still a competetive disadvantage that PHPStan doesn't understand this syntax now, so I'd like to solve it, albeit with compromises.

Copy link
Member

I've given it a little bit more thought and the problem with this implementation is that it does more than what the title says:

Allow [] after generic type or array shape

It tries to parse [] after everything, which has the problem of ambiguity. So if we limit it only to generics and array shapes for now, it should be fine?

Copy link
Collaborator

JanTvrdik commented Jan 24, 2020
edited
Loading

I still don't see how [] are ambiguous

Not syntactically ambiguous, but semantically ambiguous. Foo[] can mean either array<Foo>, iterable<Foo> of generic type (when used as part of union type).

Copy link
Member

Yeah, but we will have to live with that. It's like wishing IPv4 to die...

hrach reacted with confused emoji

Copy link
Contributor Author

I don't know what you're talking about, can you post an example?

What I meant is just that I'd prefer [] to be a packed array by default, so what Psalm considers to be a list. But that would make 90% of the array annotations in the wild incorrect.

Copy link
Contributor Author

It tries to parse [] after everything

Anything that is atomic. The problem is that callables aren't atomic. There's still a PR from @JanTvrdik to solve that.

Copy link
Member

I'll merge this if you do it only for generics and array shapes + write a test case that shows that callable(): string[] didn't change :) It has the highest potential of not breaking anything. Thanks.

@iluuu1994 iluuu1994 force-pushed the issue-36 branch 2 times, most recently from 552a664 to 93065d1 Compare January 25, 2020 20:32
Copy link
Contributor Author

Done. I also noticed the following:

callable(): int[]
// was parsed as callable: int
$this[]
// was parsed as $this
?int[]
// was parsed as ?int, is now array<int>|null analogous to Psalm

* Array shapes
* Generics
* $this
* Nullables
Copy link
Member

Thank you very much!

Copy link
Contributor Author

@ondrejmirtes You're welcome 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /