Skip to content

Commit f96a769

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 ea3c688 commit f96a769

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1331,20 +1331,20 @@ trait Checking {
13311331
}
13321332

13331333
/** Check that user-defined (result) type is fully applied */
1334-
def checkFullyAppliedType(tree: Tree)(using Context): Unit = tree match
1334+
def checkFullyAppliedType(tree: Tree, prefix: String)(using Context): Unit = tree match
13351335
case TypeBoundsTree(lo, hi, alias) =>
1336-
checkFullyAppliedType(lo)
1337-
checkFullyAppliedType(hi)
1338-
checkFullyAppliedType(alias)
1336+
checkFullyAppliedType(lo, prefix)
1337+
checkFullyAppliedType(hi, prefix)
1338+
checkFullyAppliedType(alias, prefix)
13391339
case Annotated(arg, annot) =>
1340-
checkFullyAppliedType(arg)
1340+
checkFullyAppliedType(arg, prefix)
13411341
case LambdaTypeTree(_, body) =>
1342-
checkFullyAppliedType(body)
1342+
checkFullyAppliedType(body, prefix)
13431343
case _: TypeTree =>
13441344
case _ =>
13451345
if tree.tpe.typeParams.nonEmpty then
13461346
val what = if tree.symbol.exists then tree.symbol.show else i"type $tree"
1347-
report.error(em"$what takes type parameters", tree.srcPos)
1347+
report.error(em"$prefix$what takes type parameters", tree.srcPos)
13481348

13491349
/** Check that we are in an inline context (inside an inline method or in inline code) */
13501350
def checkInInlineContext(what: String, pos: SrcPos)(using Context): Unit =
@@ -1609,7 +1609,7 @@ trait ReChecking extends Checking {
16091609
override def checkEnumParent(cls: Symbol, firstParent: Symbol)(using Context): Unit = ()
16101610
override def checkEnum(cdef: untpd.TypeDef, cls: Symbol, firstParent: Symbol)(using Context): Unit = ()
16111611
override def checkRefsLegal(tree: tpd.Tree, badOwner: Symbol, allowed: (Name, Symbol) => Boolean, where: String)(using Context): Unit = ()
1612-
override def checkFullyAppliedType(tree: Tree)(using Context): Unit = ()
1612+
override def checkFullyAppliedType(tree: Tree, prefix: String)(using Context): Unit = ()
16131613
override def checkEnumCaseRefsLegal(cdef: TypeDef, enumCtx: Context)(using Context): Unit = ()
16141614
override def checkAnnotApplicable(annot: Tree, sym: Symbol)(using Context): Boolean = true
16151615
override def checkMatchable(tp: Type, pos: SrcPos, pattern: Boolean)(using Context): Unit = ()

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2780,8 +2780,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
27802780
typeIndexedLambdaTypeTree(rhs, tparams, body)
27812781
case rhs =>
27822782
typedType(rhs)
2783-
checkFullyAppliedType(rhs1)
2784-
if sym.isOpaqueAlias then checkNoContextFunctionType(rhs1)
2783+
if sym.isOpaqueAlias then
2784+
checkFullyAppliedType(rhs1, "Opaque type alias must be fully applied, but ")
2785+
checkNoContextFunctionType(rhs1)
27852786
assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
27862787
}
27872788

tests/neg/i12456.scala

+1-1
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

+1-1
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

+1-1
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

+1-1
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

-7
This file was deleted.

tests/pos/unapplied-types.scala

+7
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)