diff options
author | Martin Odersky <odersky@gmail.com> | 2016-07-07 15:14:37 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-07-11 13:35:07 +0200 |
commit | fd62c7b6dc6882f658ba2d614cb95a7141842929 (patch) | |
tree | 961a38a2a1f2090e42162490223a627dd424cc03 /src/dotty/tools/dotc/typer/Checking.scala | |
parent | eebb4b07bf3011de56f297e7d5357cbc1ee7d623 (diff) | |
download | dotty-fd62c7b6dc6882f658ba2d614cb95a7141842929.tar.gz dotty-fd62c7b6dc6882f658ba2d614cb95a7141842929.tar.bz2 dotty-fd62c7b6dc6882f658ba2d614cb95a7141842929.zip |
Disallow higher-kinded types that simulate general existential types
We cannot handle such types in general. So we now check that a hk application
C[args]
where some of the arguments are wildcards does not have as a supertype
a hk application
([X] -> B)[args]
Diffstat (limited to 'src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 3aa63aeeb..aa13bdc3d 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -55,6 +55,24 @@ object Checking { def checkBounds(args: List[tpd.Tree], poly: GenericType)(implicit ctx: Context): Unit = checkBounds(args, poly.paramBounds, _.substParams(poly, _)) + /** If type is a higher-kinded application with wildcard arguments, + * check that it or one of its supertypes can be reduced to a normal application. + * Unreducible applications correspond to general existentials, and we + * cannot handle those. + */ + def checkWildcardHKApply(tp: Type, pos: Position)(implicit ctx: Context): Unit = tp match { + case tp @ HKApply(tycon, args) if args.exists(_.isInstanceOf[TypeBounds]) => + tycon match { + case tycon: TypeLambda => + ctx.errorOrMigrationWarning( + d"unreducible application of higher-kinded type $tycon to wildcard arguments", + pos) + case _ => + checkWildcardHKApply(tp.superType, pos) + } + case _ => + } + /** Traverse type tree, performing the following checks: * 1. All arguments of applied type trees must conform to their bounds. * 2. Prefixes of type selections and singleton types must be realizable. @@ -74,6 +92,10 @@ object Checking { val bounds = tparams.map(tparam => tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds) checkBounds(args, bounds, _.substDealias(tparams, _)) + + def checkValidIfHKApply(implicit ctx: Context): Unit = + checkWildcardHKApply(tycon.tpe.appliedTo(args.map(_.tpe)), tree.pos) + checkValidIfHKApply(ctx.addMode(Mode.AllowLambdaWildcardApply)) case Select(qual, name) if name.isTypeName => checkRealizable(qual.tpe, qual.pos) case SelectFromTypeTree(qual, name) if name.isTypeName => |