Skip to content

Commit 8698e48

Browse files
authored
Merge pull request #4360 from dotty-staging/change-kindedness
Clean up kindedness tests
2 parents 25dd1de + 2470455 commit 8698e48

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ class TypeApplications(val self: Type) extends AnyVal {
210210
/** Is self type bounded by a type lambda or AnyKind? */
211211
def isLambdaSub(implicit ctx: Context): Boolean = hkResult.exists
212212

213-
/** Is self type of kind != "*"? */
214-
def hasHigherKind(implicit ctx: Context): Boolean =
215-
typeParams.nonEmpty || self.isRef(defn.AnyKindClass)
213+
/** Is self type of kind "*"? */
214+
def hasSimpleKind(implicit ctx: Context): Boolean =
215+
typeParams.isEmpty && !self.hasAnyKind
216216

217217
/** If self type is higher-kinded, its result type, otherwise NoType.
218218
* Note: The hkResult of an any-kinded type is again AnyKind.

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

+14
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,20 @@ object Types {
248248
/** Is this type a (possibly aliased) singleton type? */
249249
def isSingleton(implicit ctx: Context) = dealias.isInstanceOf[SingletonType]
250250

251+
/** Is this type of kind `AnyKind`? */
252+
def hasAnyKind(implicit ctx: Context): Boolean = {
253+
@tailrec def loop(tp: Type): Boolean = tp match {
254+
case tp: TypeRef =>
255+
val sym = tp.symbol
256+
if (sym.isClass) sym == defn.AnyKindClass else loop(tp.superType)
257+
case tp: TypeProxy =>
258+
loop(tp.underlying)
259+
case _ =>
260+
false
261+
}
262+
loop(this)
263+
}
264+
251265
/** Is this type guaranteed not to have `null` as a value? */
252266
final def isNotNull(implicit ctx: Context): Boolean = this match {
253267
case tp: ConstantType => tp.value.value != null

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
208208
}
209209
case tree: TypeApply =>
210210
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
211-
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
211+
if (fn.symbol != defn.ChildAnnot.primaryConstructor) {
212+
// Make an exception for ChildAnnot, which should really have AnyKind bounds
213+
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
214+
}
212215
fn match {
213216
case sel: Select =>
214217
val args1 = transform(args)

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ object Checking {
3838
*/
3939
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context): Unit = {
4040
(args, boundss).zipped.foreach { (arg, bound) =>
41-
if (!bound.isLambdaSub && arg.tpe.isLambdaSub)
41+
if (!bound.isLambdaSub && !arg.tpe.hasSimpleKind) {
4242
// see MissingTypeParameterFor
4343
ctx.error(ex"missing type parameter(s) for $arg", arg.pos)
44+
}
4445
}
4546
for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate))
4647
ctx.error(
@@ -695,7 +696,7 @@ trait Checking {
695696

696697
/** Check that `tpt` does not define a higher-kinded type */
697698
def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree =
698-
if (tpt.tpe.isLambdaSub && !ctx.compilationUnit.isJava) {
699+
if (!tpt.tpe.hasSimpleKind && !ctx.compilationUnit.isJava) {
699700
// be more lenient with missing type params in Java,
700701
// needed to make pos/java-interop/t1196 work.
701702
errorTree(tpt, MissingTypeParameterFor(tpt.tpe))

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ trait TypeAssigner {
255255
*/
256256
def accessibleSelectionType(tree: untpd.RefTree, qual1: Tree)(implicit ctx: Context): Type = {
257257
var qualType = qual1.tpe.widenIfUnstable
258-
if (qualType.isLambdaSub) qualType = errorType(em"$qualType takes type parameters", qual1.pos)
258+
if (!qualType.hasSimpleKind && tree.name != nme.CONSTRUCTOR)
259+
// constructors are selected on typeconstructor, type arguments are passed afterwards
260+
qualType = errorType(em"$qualType takes type parameters", qual1.pos)
259261
else if (!qualType.isInstanceOf[TermType]) qualType = errorType(em"$qualType is illegal as a selection prefix", qual1.pos)
260262
val ownType = selectionType(qualType, tree.name, tree.pos)
261263
ensureAccessible(ownType, qual1.isInstanceOf[Super], tree.pos)

library/src/scala/annotation/internal/Child.scala

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ import scala.annotation.Annotation
1212
* Then the class symbol `A` would carry the annotations
1313
* `@Child[Bref] @Child[Cref]` where `Bref`, `Cref` are TypeRefs
1414
* referring to the class symbols of `B` and `C`
15+
* TODO: This should be `Child[T <: AnyKind]`
1516
*/
1617
class Child[T] extends Annotation

0 commit comments

Comments
 (0)