Skip to content

Commit 9587095

Browse files
committed
Fixed type adaptation problem in checkBounds
We need to adapt type parameter bounds with an as-ssen-from to the prefix of the type constructor. Makes pos/boundspropagation pass.
1 parent e6eb3bf commit 9587095

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/dotty/tools/dotc/transform/FirstTransform.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer {
126126
case tree: NamedArg => transform(tree.arg)
127127
case AppliedTypeTree(tycon, args) =>
128128
val tparams = tycon.tpe.typeSymbol.typeParams
129+
val bounds = tparams.map(tparam =>
130+
tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds)
129131
Checking.checkBounds(
130-
args, tparams.map(_.info.bounds), (tp, argTypes) => tp.substDealias(tparams, argTypes))
132+
args, bounds, (tp, argTypes) => tp.substDealias(tparams, argTypes))
131133
normalizeType(tree)
132134
case tree =>
133135
normalizeType(tree)

tests/pos/boundspropagation.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// test contributed by @retronym
2+
object test1 {
3+
class Base {
4+
type N
5+
6+
class Tree[-T >: N]
7+
8+
def f(x: Any): Tree[N] = x match {
9+
case y: Tree[_] => y
10+
}
11+
}
12+
class Derived extends Base {
13+
def g(x: Any): Tree[N] = x match {
14+
case y: Tree[_] => y // now succeeds in dotc
15+
}
16+
}
17+
}
18+

0 commit comments

Comments
 (0)