Skip to content

Commit 8329573

Browse files
committed
Fix to checkBounds
Need to account for the fact that some argument types may be TypeBoudns themselves. The change makes Jason's latest example work.
1 parent 7427c67 commit 8329573

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
141141
val tparams = tycon.tpe.typeSymbol.typeParams
142142
val bounds = tparams.map(tparam =>
143143
tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds)
144-
Checking.checkBounds(
145-
args, bounds, (tp, argTypes) => tp.substDealias(tparams, argTypes))
144+
def instantiateUpperBound(tp: Type, argTypes: List[Type]): Type = {
145+
tp.substDealias(tparams, argTypes).bounds.hi
146+
// not that argTypes can contain a TypeBounds type for arguments that are
147+
// not fully determined. In that case we need to check against the hi bound.
148+
}
149+
Checking.checkBounds(args, bounds, instantiateUpperBound)
146150
normalizeType(tree)
147151
case tree =>
148152
normalizeType(tree)

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ object Checking {
3333
/** A general checkBounds method that can be used for TypeApply nodes as
3434
* well as for AppliedTypeTree nodes.
3535
*/
36-
def checkBounds(args: List[tpd.Tree], bounds: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context) = {
36+
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context) = {
3737
val argTypes = args.tpes
38-
for ((arg, bounds) <- args zip bounds) {
38+
for ((arg, bounds) <- args zip boundss) {
3939
def notConforms(which: String, bound: Type) = {
4040
ctx.error(
4141
d"Type argument ${arg.tpe} does not conform to $which bound $bound ${err.whyNoMatchStr(arg.tpe, bound)}",

tests/pos/boundspropagation.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ object test1 {
1515
}
1616
}
1717
}
18+
object test2 {
19+
class Tree[S, T <: S]
1820

21+
class Base {
22+
def g(x: Any): Tree[_, _ <: Int] = x match {
23+
case y: Tree[Int @unchecked, _] => y
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)