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

Regression in typer for closure body treated as named tuple #21770

Closed
WojciechMazur opened this issue Oct 15, 2024 · 2 comments · Fixed by #21823
Closed

Regression in typer for closure body treated as named tuple #21770

WojciechMazur opened this issue Oct 15, 2024 · 2 comments · Fixed by #21823
Assignees
Labels
area:named-tuples Issues tied to the named tuples feature. area:typer itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB failure in scala-native/scala-native - build logs

Related #21767

Compiler version

Last good release: 3.6.0-RC1-bin-20241003-a672e05-NIGHTLY
First bad release: 3.6.0-RC1-bin-20241005-6fa81cf-NIGHTLY

Bisect points to 87cdbc8

Minimized code

@main def Test = {
  var cached: Option[scala.Double] = None
  val spliterator: java.util.Spliterator.OfDouble = ???
  spliterator.tryAdvance((e: Double) => (cached = Some(e)))
}

Output

[error] ./test.scala:4:3
[error] None of the overloaded alternatives of method tryAdvance in trait OfDouble with types
[error]  (x$0: java.util.function.Consumer[? >: Double]): Boolean
[error]  (x$0: java.util.function.DoubleConsumer): Boolean
[error] match arguments (Double² => (cached : Some[Double²]))
[error] 
[error] where:    Double  is a class in package java.lang
[error]           Double² is a class in package scala
[error]   spliterator.tryAdvance((e: Double) => (cached = Some(e)))

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:typer regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 15, 2024
@Gedochao Gedochao added the area:named-tuples Issues tied to the named tuples feature. label Oct 17, 2024
@Gedochao
Copy link
Contributor

cc @odersky

@dwijnand dwijnand changed the title Regression in typer for clouser body treated as named tuple Regression in typer for closure body treated as named tuple Oct 17, 2024
@odersky
Copy link
Contributor

odersky commented Oct 17, 2024

Yes, that will no longer work. Workarounds:

spliterator.tryAdvance((e: Double) => {cached = Some(e)})

Or, better:

spliterator.tryAdvance { (e: Double) => cached = Some(e) }

Or:

spliterator.tryAdvance: (e: Double) => 
  cached = Some(e)

Each of these is clearer than the original.

One thing we can do is a migration hint with a rewrite rule.

mbovel added a commit that referenced this issue Oct 22, 2024
This PR adds a warning for named tuples that look like assignment, such
as `(x = 1)`.

This is the first half to implement #21681. The second will be to add
warnings for named arguments to infix method calls (as a separate PR?).

Started during the Spree of October 21st.

Closes #21770.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:named-tuples Issues tied to the named tuples feature. area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants