Skip to content

Commit 18b3080

Browse files
committed
Allow hk parameters in lower bounds
1 parent 0ff5354 commit 18b3080

File tree

7 files changed

+23
-28
lines changed

7 files changed

+23
-28
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ class TypeApplications(val self: Type) extends AnyVal {
349349
case self: TypeAlias =>
350350
self.derivedTypeAlias(expand(self.alias))
351351
case self @ TypeBounds(lo, hi) =>
352-
self.derivedTypeBounds(lo, expand(hi))
352+
self.derivedTypeBounds(
353+
if (lo.isRef(defn.NothingClass)) lo else expand(lo),
354+
expand(hi))
353355
case _ => expand(self)
354356
}
355357
}
@@ -431,7 +433,7 @@ class TypeApplications(val self: Type) extends AnyVal {
431433
case arg @ TypeAlias(alias) =>
432434
arg.derivedTypeAlias(adaptArg(alias))
433435
case arg @ TypeBounds(lo, hi) =>
434-
arg.derivedTypeBounds(lo, adaptArg(hi))
436+
arg.derivedTypeBounds(adaptArg(lo), adaptArg(hi))
435437
case _ =>
436438
arg
437439
}
@@ -504,7 +506,7 @@ class TypeApplications(val self: Type) extends AnyVal {
504506
case dealiased: TypeAlias =>
505507
dealiased.derivedTypeAlias(dealiased.alias.appliedTo(args))
506508
case dealiased: TypeBounds =>
507-
dealiased.derivedTypeBounds(dealiased.lo, dealiased.hi.appliedTo(args))
509+
dealiased.derivedTypeBounds(dealiased.lo.appliedTo(args), dealiased.hi.appliedTo(args))
508510
case dealiased: LazyRef =>
509511
LazyRef(() => dealiased.ref.appliedTo(args))
510512
case dealiased: WildcardType =>

src/dotty/tools/dotc/core/Types.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2596,7 +2596,9 @@ object Types {
25962596
case resType @ TypeAlias(alias) =>
25972597
resType.derivedTypeAlias(duplicate(paramNames, paramBounds, alias))
25982598
case resType @ TypeBounds(lo, hi) =>
2599-
resType.derivedTypeBounds(lo, duplicate(paramNames, paramBounds, hi))
2599+
resType.derivedTypeBounds(
2600+
if (lo.isRef(defn.NothingClass)) lo else duplicate(paramNames, paramBounds, lo),
2601+
duplicate(paramNames, paramBounds, hi))
26002602
case _ =>
26012603
derivedGenericType(paramNames, paramBounds, resType)
26022604
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,6 @@ trait Checking {
534534
errorTree(tpt, d"missing type parameter for ${tpt.tpe}")
535535
}
536536
else tpt
537-
538-
def checkLowerNotHK(sym: Symbol, tparams: List[Symbol], pos: Position)(implicit ctx: Context) =
539-
if (tparams.nonEmpty)
540-
sym.info match {
541-
case info: TypeAlias => // ok
542-
case TypeBounds(lo, _) =>
543-
for (tparam <- tparams)
544-
if (tparam.typeRef.occursIn(lo))
545-
ctx.error(i"type parameter ${tparam.name} may not occur in lower bound $lo", pos)
546-
case _ =>
547-
}
548537
}
549538

550539
trait NoChecking extends Checking {
@@ -558,5 +547,4 @@ trait NoChecking extends Checking {
558547
override def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = ()
559548
override def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) = ()
560549
override def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = tpt
561-
override def checkLowerNotHK(sym: Symbol, tparams: List[Symbol], pos: Position)(implicit ctx: Context) = ()
562550
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10641064

10651065
def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedTypeDef") {
10661066
val TypeDef(name, rhs) = tdef
1067-
checkLowerNotHK(sym, tdef.tparams.map(symbolOfTree), tdef.pos)
10681067
completeAnnotations(tdef, sym)
10691068
assignType(cpy.TypeDef(tdef)(name, typedType(rhs), Nil), sym)
10701069
}

tests/neg/hklower.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/neg/hklower2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test { // error: conflicting bounds
2+
trait T[X]
3+
type Z[X] >: String <: T[X]
4+
}

tests/pos/hklower.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Test { // error: conflicting bounds
2+
3+
type T[X]
4+
type U[X] = T[X]
5+
6+
type V[X] >: T[X]
7+
type W[X] >: T[X] <: T[X]
8+
9+
def f[C[X] >: T[X]]() = ???
10+
11+
}

0 commit comments

Comments
 (0)