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

Assign is context-sensitive due to named arguments #8206

Closed
scabug opened this issue Jan 29, 2014 · 7 comments
Closed

Assign is context-sensitive due to named arguments #8206

scabug opened this issue Jan 29, 2014 · 7 comments

Comments

@scabug
Copy link

scabug commented Jan 29, 2014

At the moment Assign is context sensitive due to the fact that it can't be distinguished from named argument:

def f(x: Any) = x 
var x = ...
f(x = 2) 

In order to minimize ambiguity we can force people who really want to have assign in that position should add extra parens or curly braces to disambiguate:

f(x = 2) // named arg
f((x = 2)) // assign
f { x = 2 } // assign

This would allow us to replace AssignOrNamedArg tree with just NamedArg.

@scabug
Copy link
Author

scabug commented Jan 29, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8206?orig=1
Reporter: @densh
Affected Versions: 2.11.0-M8
See #8342

@scabug
Copy link
Author

scabug commented Jan 29, 2014

@retronym said:
Here's a contrived example when the intuitive interpretation is definitely assignment:

scala> object O { var x = 0 ; def foo = synchronized { x = 1 } }
defined object O

scala> O.foo; O.x
res0: Int = 1

@scabug
Copy link
Author

scabug commented Jan 29, 2014

@retronym said:
(I'm not against a move to make things unambiguous, BTW)

@scabug
Copy link
Author

scabug commented Jul 11, 2014

@densh said:
Some recent discussion on the topic: https://groups.google.com/forum/#!topic/scala-internals/MujIVZgbwEM

@scabug
Copy link
Author

scabug commented Jul 24, 2014

Ryan Hendrickson (ryan.hendrickson_bwater) said:
Man, I ran into a case today where I really wanted to write

doUpdate(_.copy(someField = _, anotherField = _))

but instead I had to write

doUpdate((a, b, c) => a.copy(someField = b, anotherField = c))

#firstworldprogrammingproblems

Not a bug, as spec'd, etc.; but am I correct in guessing that this proposed change would mean that the parser would recognize someField = _ as a named arg and not an expression, so that the former would be a valid anonymous function? Because that would be pretty nifty.

@scabug
Copy link
Author

scabug commented Jul 22, 2015

@lrytz said:
related to #8342, we plan to dis-ambiguate foo(a = x)

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue
Copy link
Member

@lrytz this is no longer applicable thanks to the ambiguity going away in 2.13, right?

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

No branches or pull requests

3 participants