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

Open
WojciechMazur opened this issue Oct 15, 2024 · 2 comments
Open

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

WojciechMazur opened this issue Oct 15, 2024 · 2 comments
Assignees
Labels
area:experimental: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:experimental: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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental: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

No branches or pull requests

4 participants