Skip to content

Commit c7e9404

Browse files
committed
Fix #8152: Fix type parameters for opaque bounds
1 parent 49247d0 commit c7e9404

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,21 @@ object SymDenotations {
483483
recur(owner.asClass.givenSelfType)
484484
end setAlias
485485

486+
def split(tp: Type): (Type, TypeBounds) = tp match
487+
case AnnotatedType(alias, Annotation.WithBounds(bounds)) =>
488+
(alias, bounds)
489+
case tp: HKTypeLambda =>
490+
val (alias1, bounds1) = split(tp.resType)
491+
(tp.derivedLambdaType(resType = alias1),
492+
HKTypeLambda.boundsFromParams(tp.typeParams, bounds1))
493+
case _ =>
494+
(tp, HKTypeLambda.boundsFromParams(tp.typeParams, TypeBounds.empty))
495+
486496
info match
487-
case TypeAlias(alias) if isOpaqueAlias && owner.isClass =>
488-
val bounds = alias match
489-
case AnnotatedType(alias1, Annotation.WithBounds(bounds)) =>
490-
setAlias(alias1)
491-
bounds
492-
case _ =>
493-
setAlias(alias)
494-
TypeBounds.empty
495-
HKTypeLambda.boundsFromParams(alias.typeParams, bounds)
497+
case TypeAlias(tp) if isOpaqueAlias && owner.isClass =>
498+
val (alias, bounds) = split(tp)
499+
setAlias(alias)
500+
bounds
496501
case _ =>
497502
info
498503
end opaqueToBounds

tests/pos/i8152.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object opaque {
2+
opaque type Foo[X] <: String = String
3+
}
4+
object test {
5+
val s: String = ???.asInstanceOf[opaque.Foo[String]]
6+
}
7+
object opaque2 {
8+
opaque type Foo2 <: String = String
9+
}
10+
object test2 {
11+
val s: String = "bla"
12+
}

tests/pos/opaque-simple.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object O {
2+
opaque type First[A1] = A1
3+
opaque type Last[A] = A
4+
}

0 commit comments

Comments
 (0)