Skip to content

Commit 6929958

Browse files
committed
Address reviewer comments
1 parent 48ed3c6 commit 6929958

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ object Contexts {
532532
moreProperties = Map.empty
533533
typeComparer = new TypeComparer(this)
534534
searchHistory = new SearchHistory(0, Map())
535-
gadt = new GADTMap(SimpleMap.Empty) // EmptyGADTMap
535+
gadt = EmptyGADTMap
536536
}
537537

538538
@sharable object NoContext extends Context {

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

+9-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTrans
256256
case tree @ Annotated(annotated, annot) =>
257257
cpy.Annotated(tree)(transform(annotated), transformAnnot(annot))
258258
case tree: AppliedTypeTree =>
259-
Checking.checkAppliedType(tree)
259+
Checking.checkAppliedType(tree, boundsCheck = !ctx.mode.is(Mode.Pattern))
260260
super.transform(tree)
261261
case SingletonTypeTree(ref) =>
262262
Checking.checkRealizable(ref.tpe, ref.pos.focus)
@@ -282,7 +282,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTrans
282282
}
283283
super.transform(tree)
284284
case Typed(Ident(nme.WILDCARD), _) =>
285-
tree // skip checking pattern type
285+
super.transform(tree)(ctx.addMode(Mode.Pattern))
286+
// The added mode signals that bounds in a pattern need not
287+
// conform to selector bounds. I.e. assume
288+
// type Tree[T >: Null <: Type]
289+
// One is still allowed to write
290+
// case x: Tree[_]
291+
// (which translates to)
292+
// case x: (_: Tree[_])
286293
case tree =>
287294
super.transform(tree)
288295
}

compiler/src/dotty/tools/dotc/typer/Checking.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object Checking {
6868
* Unreducible applications correspond to general existentials, and we
6969
* cannot handle those.
7070
*/
71-
def checkAppliedType(tree: AppliedTypeTree)(implicit ctx: Context) = {
71+
def checkAppliedType(tree: AppliedTypeTree, boundsCheck: Boolean)(implicit ctx: Context) = {
7272
val AppliedTypeTree(tycon, args) = tree
7373
// If `args` is a list of named arguments, return corresponding type parameters,
7474
// otherwise return type parameters unchanged
@@ -81,7 +81,7 @@ object Checking {
8181
val bounds = tparams.map(_.paramInfoAsSeenFrom(tycon.tpe).bounds)
8282
def instantiate(bound: Type, args: List[Type]) =
8383
HKTypeLambda.fromParams(tparams, bound).appliedTo(args)
84-
checkBounds(orderedArgs, bounds, instantiate)
84+
if (boundsCheck) checkBounds(orderedArgs, bounds, instantiate)
8585

8686
def checkWildcardApply(tp: Type, pos: Position): Unit = tp match {
8787
case tp @ AppliedType(tycon, args) if args.exists(_.isInstanceOf[TypeBounds]) =>

0 commit comments

Comments
 (0)