Skip to content

Commit df7a092

Browse files
committed
Drop restriction against typedefs at level * only
Allow the RHS of a type def to be higher-kinded. But keep the restriction for opaque type aliases; their RHS must be fully applied. I am not sure why the restriction applies to them, but there was a test specifically about that, so there night be a reason. # Conflicts: # compiler/src/dotty/tools/dotc/typer/Typer.scala # Conflicts: # compiler/src/dotty/tools/dotc/typer/Typer.scala # tests/pos/typeclasses-this.scala
1 parent 3f8094e commit df7a092

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,20 +1325,20 @@ trait Checking {
13251325
}
13261326

13271327
/** Check that user-defined (result) type is fully applied */
1328-
def checkFullyAppliedType(tree: Tree)(using Context): Unit = tree match
1328+
def checkFullyAppliedType(tree: Tree, prefix: String)(using Context): Unit = tree match
13291329
case TypeBoundsTree(lo, hi, alias) =>
1330-
checkFullyAppliedType(lo)
1331-
checkFullyAppliedType(hi)
1332-
checkFullyAppliedType(alias)
1330+
checkFullyAppliedType(lo, prefix)
1331+
checkFullyAppliedType(hi, prefix)
1332+
checkFullyAppliedType(alias, prefix)
13331333
case Annotated(arg, annot) =>
1334-
checkFullyAppliedType(arg)
1334+
checkFullyAppliedType(arg, prefix)
13351335
case LambdaTypeTree(_, body) =>
1336-
checkFullyAppliedType(body)
1336+
checkFullyAppliedType(body, prefix)
13371337
case _: TypeTree =>
13381338
case _ =>
13391339
if tree.tpe.typeParams.nonEmpty then
13401340
val what = if tree.symbol.exists then tree.symbol.show else i"type $tree"
1341-
report.error(em"$what takes type parameters", tree.srcPos)
1341+
report.error(em"$prefix$what takes type parameters", tree.srcPos)
13421342

13431343
/** Check that we are in an inline context (inside an inline method or in inline code) */
13441344
def checkInInlineContext(what: String, pos: SrcPos)(using Context): Unit =
@@ -1603,7 +1603,7 @@ trait ReChecking extends Checking {
16031603
override def checkEnumParent(cls: Symbol, firstParent: Symbol)(using Context): Unit = ()
16041604
override def checkEnum(cdef: untpd.TypeDef, cls: Symbol, firstParent: Symbol)(using Context): Unit = ()
16051605
override def checkRefsLegal(tree: tpd.Tree, badOwner: Symbol, allowed: (Name, Symbol) => Boolean, where: String)(using Context): Unit = ()
1606-
override def checkFullyAppliedType(tree: Tree)(using Context): Unit = ()
1606+
override def checkFullyAppliedType(tree: Tree, prefix: String)(using Context): Unit = ()
16071607
override def checkEnumCaseRefsLegal(cdef: TypeDef, enumCtx: Context)(using Context): Unit = ()
16081608
override def checkAnnotApplicable(annot: Tree, sym: Symbol)(using Context): Boolean = true
16091609
override def checkMatchable(tp: Type, pos: SrcPos, pattern: Boolean)(using Context): Unit = ()

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,8 +2704,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
27042704
typeIndexedLambdaTypeTree(rhs, tparams, body)
27052705
case rhs =>
27062706
typedType(rhs)
2707-
checkFullyAppliedType(rhs1)
2708-
if sym.isOpaqueAlias then checkNoContextFunctionType(rhs1)
2707+
if sym.isOpaqueAlias then
2708+
checkFullyAppliedType(rhs1, "Opaque type alias must be fully applied, but ")
2709+
checkNoContextFunctionType(rhs1)
27092710
assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
27102711
}
27112712

tests/neg/i12456.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
object F { type T[G[X] <: X, F <: G[F]] } // error // error
1+
object F { type T[G[X] <: X, F <: G[F]] } // error

tests/neg/i13757-match-type-anykind.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test:
88
type AnyKindMatchType3[X <: AnyKind] = X match // error: the scrutinee of a match type cannot be higher-kinded
99
case _ => Int
1010

11-
type AnyKindMatchType4[X <: Option] = X match // error // error: the scrutinee of a match type cannot be higher-kinded
11+
type AnyKindMatchType4[X <: Option] = X match // error: the scrutinee of a match type cannot be higher-kinded
1212
case _ => Int
1313

1414
type AnyKindMatchType5[X[_]] = X match // error: the scrutinee of a match type cannot be higher-kinded

tests/neg/i9328.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type Id[T] = T match {
33
case _ => T
44
}
55

6-
class Foo2[T <: Id[T]] // error // error
6+
class Foo2[T <: Id[T]] // error
77

88
object Foo { // error
99
object Foo { }

tests/neg/parser-stability-12.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
trait x0[]: // error
2-
trait x1[x1 <:x0] // error: type x0 takes type parameters
2+
trait x1[x1 <:x0]
33
extends x1[ // error
44
// error

tests/neg/unapplied-types.scala

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

tests/pos/unapplied-types.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait T {
2+
type L[X] = List[X]
3+
type T1 <: L // was error: takes type parameters
4+
type T2 = L // was error: takes type parameters
5+
type T3 = List // was error: takes type parameters
6+
type T4 <: List // was error: takes type parameters
7+
}

0 commit comments

Comments
 (0)