Skip to content

Extension method lookup failure when the receiver type is path-dependent on a using parameter and the extension comes from a given looked up based on the implicit scope of the type of the receiver #18888

Open
@smarter

Description

@smarter

Compiler version

3.3.1

Minimized code

trait Context:
  type Elem[T]

trait TypeClass[T]:
  extension (using nb: Context)(x: nb.Elem[T])
    def tcMeth: T


class Bla
object Bla:
  given fb: TypeClass[Bla] = ???

class Wrapper[T]
object Wrapper:
  given fa[T](using TypeClass[T]): TypeClass[Wrapper[T]] = ???


object Test:
  def test1(using nb: Context) =
    val x1: nb.Elem[Bla] = ???
    val x2: nb.Elem[Wrapper[Bla]] = ???
    x1.tcMeth // ok
    x2.tcMeth // error
    summon[TypeClass[Wrapper[Bla]]].tcMeth(x2) // ok

  def test2(using nb: Context, tc: TypeClass[Wrapper[Bla]]) =
    val y: nb.Elem[Wrapper[Bla]] = ???
    y.tcMeth // ok

Output

-- [E008] Not Found Error: tests/pos/extgiven.scala:23:7 -----------------------
23 |    x2.tcMeth // error
   |    ^^^^^^^^^
   |    value tcMeth is not a member of nb.Elem[Wrapper[Bla]].
   |    An extension method was tried, but could not be fully constructed:
   |
   |        Wrapper.fa[T](/* missing */summon[TypeClass[T]]).tcMeth()

Expectation

x2.tcMeth should typecheck since summon[TypeClass[Wrapper[Bla]]].tcMeth(x2) does typecheck and the summoned instance is Wrapper.fa which is in the implicit scope of the type of x2.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions