diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 6a144f0edbbc..f589001303a0 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -532,7 +532,7 @@ object Contexts { moreProperties = Map.empty typeComparer = new TypeComparer(this) searchHistory = new SearchHistory(0, Map()) - gadt = new GADTMap(SimpleMap.Empty) // EmptyGADTMap + gadt = EmptyGADTMap } @sharable object NoContext extends Context { diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 2d7610e1fd1a..0625242adbc0 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -256,7 +256,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTrans case tree @ Annotated(annotated, annot) => cpy.Annotated(tree)(transform(annotated), transformAnnot(annot)) case tree: AppliedTypeTree => - Checking.checkAppliedType(tree) + Checking.checkAppliedType(tree, boundsCheck = !ctx.mode.is(Mode.Pattern)) super.transform(tree) case SingletonTypeTree(ref) => Checking.checkRealizable(ref.tpe, ref.pos.focus) @@ -282,7 +282,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTrans } super.transform(tree) case Typed(Ident(nme.WILDCARD), _) => - tree // skip checking pattern type + super.transform(tree)(ctx.addMode(Mode.Pattern)) + // The added mode signals that bounds in a pattern need not + // conform to selector bounds. I.e. assume + // type Tree[T >: Null <: Type] + // One is still allowed to write + // case x: Tree[_] + // (which translates to) + // case x: (_: Tree[_]) case tree => super.transform(tree) } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 3c60db0e0ec1..27b685a19299 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -68,7 +68,7 @@ object Checking { * Unreducible applications correspond to general existentials, and we * cannot handle those. */ - def checkAppliedType(tree: AppliedTypeTree)(implicit ctx: Context) = { + def checkAppliedType(tree: AppliedTypeTree, boundsCheck: Boolean)(implicit ctx: Context) = { val AppliedTypeTree(tycon, args) = tree // If `args` is a list of named arguments, return corresponding type parameters, // otherwise return type parameters unchanged @@ -81,7 +81,7 @@ object Checking { val bounds = tparams.map(_.paramInfoAsSeenFrom(tycon.tpe).bounds) def instantiate(bound: Type, args: List[Type]) = HKTypeLambda.fromParams(tparams, bound).appliedTo(args) - checkBounds(orderedArgs, bounds, instantiate) + if (boundsCheck) checkBounds(orderedArgs, bounds, instantiate) def checkWildcardApply(tp: Type, pos: Position): Unit = tp match { case tp @ AppliedType(tycon, args) if args.exists(_.isInstanceOf[TypeBounds]) =>