aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Checking.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-14 18:06:48 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-14 19:52:22 +0200
commit82fc27f0c2c800de786b54110cfd8627b043fe6d (patch)
tree92bff1bc2f6869495e46fd77a1220153c25b46ac /src/dotty/tools/dotc/typer/Checking.scala
parent18b30803952cee83580eab28068bc773fdce780e (diff)
downloaddotty-82fc27f0c2c800de786b54110cfd8627b043fe6d.tar.gz
dotty-82fc27f0c2c800de786b54110cfd8627b043fe6d.tar.bz2
dotty-82fc27f0c2c800de786b54110cfd8627b043fe6d.zip
Fix bounds checking of hk applied typed
Previous logic could only handle classes as constructors. Also, address other reviewers comments.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index 9e55216c1..b1cceea88 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -83,15 +83,16 @@ object Checking {
case AppliedTypeTree(tycon, args) =>
// If `args` is a list of named arguments, return corresponding type parameters,
// otherwise return type parameters unchanged
- def matchNamed(tparams: List[TypeSymbol], args: List[Tree]): List[Symbol] =
- if (hasNamedArg(args))
- for (NamedArg(name, _) <- args) yield tycon.tpe.member(name).symbol
- else
- tparams
- val tparams = matchNamed(tycon.tpe.typeSymbol.typeParams, args)
- val bounds = tparams.map(tparam =>
- tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds)
- checkBounds(args, bounds, _.substDealias(tparams, _))
+ val tparams = tycon.tpe.typeParams
+ def argNamed(tparam: TypeParamInfo) = args.find {
+ case NamedArg(name, _) => name == tparam.paramName
+ case _ => false
+ }.getOrElse(TypeTree(tparam.paramRef))
+ val orderedArgs = if (hasNamedArg(args)) tparams.map(argNamed) else args
+ val bounds = tparams.map(_.paramBoundsAsSeenFrom(tycon.tpe))
+ def instantiate(bound: Type, args: List[Type]) =
+ bound.LambdaAbstract(tparams).appliedTo(args)
+ checkBounds(orderedArgs, bounds, instantiate)
def checkValidIfHKApply(implicit ctx: Context): Unit =
checkWildcardHKApply(tycon.tpe.appliedTo(args.map(_.tpe)), tree.pos)