Skip to content

Commit d1a5276

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 798f4f2 commit d1a5276

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
@@ -1322,20 +1322,20 @@ trait Checking {
13221322
}
13231323

13241324
/** Check that user-defined (result) type is fully applied */
1325-
def checkFullyAppliedType(tree: Tree)(using Context): Unit = tree match
1325+
def checkFullyAppliedType(tree: Tree, prefix: String)(using Context): Unit = tree match
13261326
case TypeBoundsTree(lo, hi, alias) =>
1327-
checkFullyAppliedType(lo)
1328-
checkFullyAppliedType(hi)
1329-
checkFullyAppliedType(alias)
1327+
checkFullyAppliedType(lo, prefix)
1328+
checkFullyAppliedType(hi, prefix)
1329+
checkFullyAppliedType(alias, prefix)
13301330
case Annotated(arg, annot) =>
1331-
checkFullyAppliedType(arg)
1331+
checkFullyAppliedType(arg, prefix)
13321332
case LambdaTypeTree(_, body) =>
1333-
checkFullyAppliedType(body)
1333+
checkFullyAppliedType(body, prefix)
13341334
case _: TypeTree =>
13351335
case _ =>
13361336
if tree.tpe.typeParams.nonEmpty then
13371337
val what = if tree.symbol.exists then tree.symbol.show else i"type $tree"
1338-
report.error(em"$what takes type parameters", tree.srcPos)
1338+
report.error(em"$prefix$what takes type parameters", tree.srcPos)
13391339

13401340
/** Check that we are in an inline context (inside an inline method or in inline code) */
13411341
def checkInInlineContext(what: String, pos: SrcPos)(using Context): Unit =
@@ -1600,7 +1600,7 @@ trait ReChecking extends Checking {
16001600
override def checkEnumParent(cls: Symbol, firstParent: Symbol)(using Context): Unit = ()
16011601
override def checkEnum(cdef: untpd.TypeDef, cls: Symbol, firstParent: Symbol)(using Context): Unit = ()
16021602
override def checkRefsLegal(tree: tpd.Tree, badOwner: Symbol, allowed: (Name, Symbol) => Boolean, where: String)(using Context): Unit = ()
1603-
override def checkFullyAppliedType(tree: Tree)(using Context): Unit = ()
1603+
override def checkFullyAppliedType(tree: Tree, prefix: String)(using Context): Unit = ()
16041604
override def checkEnumCaseRefsLegal(cdef: TypeDef, enumCtx: Context)(using Context): Unit = ()
16051605
override def checkAnnotApplicable(annot: Tree, sym: Symbol)(using Context): Boolean = true
16061606
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
@@ -2700,8 +2700,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
27002700
typeIndexedLambdaTypeTree(rhs, tparams, body)
27012701
case rhs =>
27022702
typedType(rhs)
2703-
checkFullyAppliedType(rhs1)
2704-
if sym.isOpaqueAlias then checkNoContextFunctionType(rhs1)
2703+
if sym.isOpaqueAlias then
2704+
checkFullyAppliedType(rhs1, "Opaque type alias must be fully applied, but ")
2705+
checkNoContextFunctionType(rhs1)
27052706
assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
27062707
}
27072708

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)