Skip to content

Associated types become opaque with indirection #21416

Closed as not planned
Closed as not planned
@farnoy

Description

@farnoy

Compiler version

3.4.2, 3.5.1-RC2

Minimized code

trait First[T]:
  type AssociatedFirst

trait Second[T]:
  type AssociatedSecond

given [T](using first: First[T]): Second[T] with
  type AssociatedSecond = first.AssociatedFirst

case class Test1()

given First[Test1] with
  type AssociatedFirst = String

val first = summon[First[Test1]]
val second = summon[Second[Test1]]
val str1: first.AssociatedFirst = "test1"
val str2: second.AssociatedSecond = "test1"

Output

-- [E007] Type Mismatch Error: -------------------------------------------------
1 |val str2: second.AssociatedSecond = "test1"
  |                                    ^^^^^^^
  |                                    Found:    ("test1" : String)
  |                                    Required: second.AssociatedSecond
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: "test1"
  | I tried to show that
  |   ("test1" : String)
  | conforms to
  |   second.AssociatedSecond
  | but none of the attempts shown below succeeded:
  |
  |   ==> ("test1" : String)  <:  second.AssociatedSecond
  |     ==> ("test1" : String)  <:  second.first.AssociatedFirst
  |       ==> String  <:  second.first.AssociatedFirst  = false
  |     ==> ("test1" : String)  <:  second.first.AssociatedFirst
  |       ==> String  <:  second.first.AssociatedFirst  = false
  |     ==> String  <:  second.AssociatedSecond
  |       ==> String  <:  second.first.AssociatedFirst  = false
  |       ==> String  <:  second.first.AssociatedFirst  = false
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
1 error found

Expectation

I expected the compiler to be able to resolve second.AssociatedSecond as String but it seems that the associated type does not reduce.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions