scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Compiler doesn't search implicit scope for + operator with -Xsource:3 enabled #13004

Closed vladimirkl closed 2 weeks ago

vladimirkl commented 3 weeks ago

Reproduction steps

Scala version: 2.13.14 with -Xsource:3 enabled

scala>   case class Money(value: Double)
     |   object Money {
     |     implicit class MoneySyntax(private val self: Money)  extends AnyVal {
     |       def +(other: Money): Money = Money(self.value + other.value)
     |     }
     |   }
     |
class Money
object Money

scala> Money(1) + Money(2)
                       ^
       error: type mismatch;
        found   : Money
        required: String
            ^
       error: Converting to String for concatenation is not supported in Scala 3 (or with -Xsource-features:any2stringadd).
       Scala 3 migration messages are issued as errors under -Xsource:3. Use -Wconf or @nowarn to demote them to warnings or suppress.
       Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=scala.Predef.any2stringadd

Problem

This example compiles perfectly using Scala 2.13.12 with -Xsource:3 enabled. Starting with 2.13.13 it fails with error above. Adding -Xsource-features:any2stringadd doesn't help - it just fails with value + is not a member of Money error. Renaming + to any other identifier fixes the issue.

som-snytt commented 3 weeks ago

On 2.13.13, it requires -Xsource:3-cross.

On 2.13.14, the check in Typer is not helpful: it ignores the undesired conversion but does not try the desired one.

vladimirkl commented 3 weeks ago

Do you mean that Typer has a bug in 2.13.14?

som-snytt commented 3 weeks ago

yes, it's a bug on 2.13.14.