Skip to content

Commit

Permalink
Fix opacity of opaque types on Scala 3
Browse files Browse the repository at this point in the history
For `opaque type S = String` generate tag `S` instead of `S::<String..String>`

Breaks compatibility with previously generated tags
  • Loading branch information
neko-kai committed Jul 1, 2024
1 parent 0810870 commit bbb841f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ abstract class Inspector(protected val shift: Int, val context: Queue[Inspector.
makeNameReferenceFromSymbol(symbol, prefixSource)

case s if s.isTypeDef =>
log(s"inspectSymbol: Found TypeDef symbol $s")
val rhs = s.typeRef._underlying
val rhs = outerTypeRef match {
case Some(r) if r.isOpaqueAlias => r._underlying
case _ => s.typeRef._underlying
}
log(s"inspectSymbol: Found TypeDef symbol $s (rhs=$rhs)")
next().inspectTypeRepr(rhs, outerTypeRef)

case s if s.isDefDef =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ class LightTypeTagTest extends SharedLightTypeTagTest {
assertChildStrict(LTT[LightTypeTagTestT], LTT[String])
}

"support opaque types" in {
object x {
type T >: List[Int] <: List[Int]
opaque type Opaque = List[Int]
opaque type OpaqueSub <: List[Int] = List[Int]
}

assertNotChildStrict(LTT[x.Opaque], LTT[List[Int]])
assertNotChildStrict(LTT[x.Opaque], LTT[Seq[Int]])
assertNotChildStrict(LTT[x.Opaque], LTT[x.T])
assertNotChildStrict(LTT[x.Opaque], LTT[x.OpaqueSub])

assertChildStrict(LTT[x.OpaqueSub], LTT[List[Int]])
assertChildStrict(LTT[x.OpaqueSub], LTT[Seq[Int]])
assertChildStrict(LTT[x.T], LTT[Seq[Int]])
assertChildStrict(LTT[x.OpaqueSub], LTT[x.T])
assertDifferent(LTT[x.OpaqueSub], LTT[x.T])
}

}
}

Expand Down

0 comments on commit bbb841f

Please # to comment.