Weird behaviour when attempting partial application with named argument method.
See original GitHub issueCompiler version
3.0.0-RC1
Minimized code
case class State(text: String):
// val updateText = copy(text = _) // Missing parameter type: I could not infer the type of the parameter _$1
val updateText = copy(text = (_: String))
scastie: https://scastie.scala-lang.org/a93h61tfRaeBBCqslsQgkg
Output
[error] -- [E052] Type Error: /<redacted>/State.scala:4:29
[error] 4 | val updateText = copy(text = (_: String))
[error] | ^^^^^^^^^^^^^^^^^^
[error] | Reassignment to val text
[error] one error found
[error] one error found
Expectation
I’d expect this to work, but in case it is difficult to support partial application and named default arguments I’d like to see a more specific error message. In any case the parser should not see this as a reassignment in the context of a method call.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
What do you guys think about the partial function application rfc?
Partial application means you can freely write functions with lots of arguments which you partially apply in a series of steps until you...
Read more >Partial application with named parameters - scala
Syntactically, underscore is bound at the enclosing expression, and assignment is an expression. So your example expands to Foo(x => a = x, ......
Read more >Partial Application in JavaScript - Ben Alman
The following partial function returns a function ƒ that, when invoked, invokes the fn function with the originally-specified (bound) arguments, ...
Read more >Partial Application vs Parameters - which do you prefer?
Partial application though, means to not provide all arguments right now and get a function back, which takes the remaining arguments. Partial ...
Read more >Partial Application - F# for fun and profit
This technique is called “partial application”, and it means that, for any function, you can “fix” some of the parameters and leave other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My previous comment in the middle of the night wasn’t clear that I don’t disagree with the intuition that it should just work.
I saw (because I had to look) that the spec isn’t clear about the syntax here. (There is no special production for named arg.)
Probably it could be made to work. The confusion around assignment syntax is just “for historical reasons.”
The most effective rule to follow is: when surprised by an error message affecting an expression with
_
, try to expand as a lambda and try again.