Skip to content

wrong you can simply leave out the trailing _ message #23281

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

Open
xuwei-k opened this issue May 29, 2025 · 2 comments
Open

wrong you can simply leave out the trailing _ message #23281

xuwei-k opened this issue May 29, 2025 · 2 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented May 29, 2025

Compiler version

  • 3.7.0
  • 3.7.1-RC2

Minimized example

Welcome to Scala 3.7.1-RC2 (21.0.7, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                             
scala> trait A[B] { def f(x: String): B }
// defined trait A
                                                                                                                                             
scala> case class C(value: String)
// defined case class C
                                                                                                                                             
scala> val x: A[C] = C.apply _
1 warning found
-- Warning: --------------------------------------------------------------------
1 |val x: A[C] = C.apply _
  |              ^^^^^^^^^
  |              The syntax `<function> _` is no longer supported;
  |              you can simply leave out the trailing ` _`
val x: A[C] = Lambda/0x00000003015984c8@1d6a22dd
                                                                                                                                             
scala> val x: A[C] = C.apply
1 warning found
-- Warning: --------------------------------------------------------------------
1 |val x: A[C] = C.apply
  |              ^^^^^^^
  |method apply is eta-expanded even though A[C] does not have the @FunctionalInterface annotation.
val x: A[C] = Lambda/0x00000003015c1400@68a94e58

Why this Error/Warning was not helpful

compiler report another warning if remove _

@xuwei-k xuwei-k added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc stat:needs triage Every issue needs to have an "area" and "itype" label better-errors Issues concerned with improving confusing/unhelpful diagnostic messages labels May 29, 2025
@som-snytt
Copy link
Contributor

It's OK to get a second warning, but that message was changed in Scala 2 to be more instructional:

t11644a.scala:24: warning: Eta-expansion to expected type AcciSamOne, which is not a function type but is SAM-convertible to Int => Int.
trait AcciSamOne should be annotated with `@FunctionalInterface` if eta-expansion is desired.
Avoid eta-expansion by writing the function literal `((x: Int) => m3(x))` or `m3(_)`.
This warning can be filtered with `-Wconf:cat=lint-eta-sam`.
  val t3AcciSam: AcciSamOne = m3  // warn

scala/bug#11644

That ticket links to the motivating Scala 3 discussions.

@som-snytt
Copy link
Contributor

som-snytt commented May 29, 2025

More annoying is that -source:3.4-migration -rewrite produces C.apply.

Relatedly, the auto-insert says

8 |val ss = List("42").map(C)
  |                        ^
  |The method `apply` is inserted. The auto insertion will be deprecated, please write `C.apply` explicitly.

@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

3 participants