Skip to content

Commit b0a6783

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 5222c11 commit b0a6783

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
@@ -128,8 +128,12 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer {
128128
val tparams = tycon.tpe.typeSymbol.typeParams
129129
val bounds = tparams.map(tparam =>
130130
tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds)
131-
Checking.checkBounds(
132-
args, bounds, (tp, argTypes) => tp.substDealias(tparams, argTypes))
131+
def instantiateUpperBound(tp: Type, argTypes: List[Type]): Type = {
132+
tp.substDealias(tparams, argTypes).bounds.hi
133+
// not that argTypes can contain a TypeBounds type for arguments that are
134+
// not fully determined. In that case we need to check against the hi bound.
135+
}
136+
Checking.checkBounds(args, bounds, instantiateUpperBound)
133137
normalizeType(tree)
134138
case tree =>
135139
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)