Skip to content

Opaque type not transparent in its defining scope, when referred to via qualified name #19609

Closed
@TomasMikula

Description

@TomasMikula

Compiler version

3.3.1
3.3.2-RC3
3.4.0-RC4

Minimized code

object o {
  opaque type T = String

  summon[o.T =:= T]      // OK
  summon[o.T =:= String] // OK

  def test1(t: T): Int =
    t.length // OK

  def test2(t: o.T): Int =
    t.length // Error: value length is not a member of Playground.o.T
}

https://scastie.scala-lang.org/CN2ydzIkSBSKNUsY10NYgQ

Output

value length is not a member of Playground.o.T

Expectation

According to https://docs.scala-lang.org/scala3/reference/other-new-features/opaques-details.html#type-checking-10

we have inside the object (also for non-opaque types) that o.T is equal to T or its expanded form o.this.T. Equality is understood here as mutual subtyping, i.e. o.T <: o.this.T and o.this.T <: o.T. Furthermore, we have by the rules of opaque type aliases that o.this.T equals R. The two equalities compose. That is, inside o, it is also known that o.T is equal to R.

it should hold, inside the object o, that o.T is equal to o.this.T is equal to String. Therefore, t.length should typecheck.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions