Skip to content

extension method hides overridden method via Conversion + a conflicting message #22267

Open
@sjbiaga

Description

@sjbiaga

Compiler version

3.6.3-RC1

Minimized code

case class M[T](var value: T)
given [T]: Conversion[M[T], T] = _.value
class C { def m(n: Double): Unit = println(0->n) }
extension (self: C) def m(n: Int): Unit = println(1->n)

REPL session

scala> val c = new M(new C)
val c: M[C] = M(rs$line$3$C@4e26c308)
scala> c.value.m(1)
(0,1.0)
scala> c.value.m(1.0)
(0,1.0)
scala> c.m(1.0)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 |c.m(1.0)
  |    ^^^
  |    Found:    (1.0d : Double)
  |    Required: Int
  |
  | longer explanation available when compiling with `-explain`
there was 1 feature warning; re-run with -feature for details
1 warning found
1 error found
                                                                                                                               
scala> c.m(1)
(1,1)
there was 1 feature warning; re-run with -feature for details
1 warning found

Now, if I add an extension with n: Double, there is even a weird message, because what happens is not what it says.

scala> extension (self: C) def m(n: Double): Unit = println(2->n)
1 warning found
-- [E194] Potential Issue Warning: ---------------------------------------------
1 |extension (self: C) def m(n: Double): Unit = println(2->n)
  |                        ^
  |Extension method m will never be selected
  |because rs$line$3$C already has a member with the same name and compatible parameter types.
  |
  | longer explanation available when compiling with `-explain`
def m(self: C)(n: Double): Unit
                                                                                                                               
scala> c.m(1.0)
(2,1.0)

Expectation

scala> c.m(1.0)
(0,1.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:extension-methodsarea:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions