question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird behaviour when attempting partial application with named argument method.

See original GitHub issue

Compiler 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
som-snyttcommented, Mar 1, 2021

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.”

0reactions
oderskycommented, Mar 5, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found