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

Fix #9829: Allow as in place of @ for pattern bindings #9837

Merged
merged 2 commits into from
Sep 24, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 20, 2020

For 3.0: Can use either @ or as.
For 3.1: @ is deprecated.

@som-snytt
Copy link
Contributor

"At-less shrugged."

@AdamPaynter
Copy link

I rather like this change. as definitely carries more explanatory value than @. My only tiny stumbling block is where the as keyword appears. Wouldn't it make more sense to say Pattern(...) as myVar instead of myVar as Pattern(...)? Don't get me wrong, if I could happily accept an arbitrary @, I can more than happily accept the as presented here. I was just curious if you could help me understand the choice.

@som-snytt
Copy link
Contributor

@AdamPaynter the issue suggests https://dotty.epfl.ch/docs/reference/contextual/givens.html as a model for the order. I had the same reservation, given usages in other domains. But if I say, "I took you for a bounder," then it's the alias taken as a bounder, the underlying type. Similarly for any definition where the lhs introduces the binding and the rhs the definition.

@odersky
Copy link
Contributor Author

odersky commented Sep 21, 2020

I think it can go both ways. ML uses <pattern> as <var>. By contrast Visual Basic uses <var> As <type> as a binder (where we would use :).

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

case p @ Ident(name) if in.token == AT || in.isIdent(nme.as) =>
if in.token == AT && sourceVersion.isAtLeast(`3.1`) then
deprecationWarning(s"`@` bindings have been deprecated; use `as` instead", in.offset)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the syntax.md file with the syntax change.

@nafg
Copy link

nafg commented Sep 24, 2020 via email

@odersky odersky merged commit 959cab4 into scala:master Sep 24, 2020
@odersky odersky deleted the fix-#9829 branch September 24, 2020 19:00
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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 this pull request may close these issues.

6 participants