diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-30 16:10:13 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2016-01-18 16:49:16 +0100 |
commit | 39ca54fcbe21df0fd277ab9734a032d71027fa4c (patch) | |
tree | d1ad29ce0293a05daab5e82d94dad1e881295605 /src/dotty/tools/dotc/typer | |
parent | c0b545be494bc53f9839c8301cdca71edeb620c7 (diff) | |
download | dotty-39ca54fcbe21df0fd277ab9734a032d71027fa4c.tar.gz dotty-39ca54fcbe21df0fd277ab9734a032d71027fa4c.tar.bz2 dotty-39ca54fcbe21df0fd277ab9734a032d71027fa4c.zip |
Check bounds everywhere
Previously, bounds of a TypeDef tree were not checked. We now make
sure bounds are checked everywhere in PostTyper. The previous
partial check in Applications gets removed (it was not complete
even for TypeApplications because sometimes bounds were not yet
known when the test was performed.)
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 12 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index b3cda20b8..649b8088f 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -607,7 +607,6 @@ trait Applications extends Compatibility { self: Typer => case pt: PolyType => if (typedArgs.length <= pt.paramBounds.length) typedArgs = typedArgs.zipWithConserve(pt.paramBounds)(adaptTypeArg) - Checking.checkBounds(typedArgs, pt) case _ => } assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs) diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 6ded7c109..3e829eb50 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -48,6 +48,18 @@ object Checking { def checkBounds(args: List[tpd.Tree], poly: PolyType)(implicit ctx: Context): Unit = checkBounds(args, poly.paramBounds, _.substParams(poly, _)) + /** Check all AppliedTypeTree nodes in this tree for legal bounds */ + val boundsChecker = new TreeTraverser { + def traverse(tree: Tree)(implicit ctx: Context) = tree match { + case AppliedTypeTree(tycon, args) => + val tparams = tycon.tpe.typeSymbol.typeParams + val bounds = tparams.map(tparam => + tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds) + checkBounds(args, bounds, _.substDealias(tparams, _)) + case _ => traverseChildren(tree) + } + } + /** Check that `tp` refers to a nonAbstract class * and that the instance conforms to the self type of the created class. */ |