Skip to content

Commit 5e4ef6d

Browse files
committed
Tighten checkBounds
Also disallow unapplied classes if bounds are first-kinded. This broke the Child annotation which should really be kind polymorphic. Fixed for now by making a special exception for Child.
1 parent 9a9de0c commit 5e4ef6d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
213213
}
214214
case tree: TypeApply =>
215215
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
216-
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
216+
if (fn.symbol != defn.ChildAnnot.primaryConstructor) {
217+
// Make an exception for ChildAnnot, which should really have AnyKind bounds
218+
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
219+
}
217220
fn match {
218221
case sel: Select =>
219222
val args1 = transform(args)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ object Checking {
4646
*/
4747
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context): Unit = {
4848
(args, boundss).zipped.foreach { (arg, bound) =>
49-
if (!bound.isLambdaSub && arg.tpe.isLambdaSub)
49+
if (!bound.isLambdaSub && arg.tpe.hasHigherKind) {
5050
// see MissingTypeParameterFor
51+
if (!arg.tpe.isLambdaSub) { // FIXME: Provisional, remove
52+
println(i"different for checkBounds $arg vs $bound at ${ctx.phase} in ${ctx.owner.ownersIterator.toList}")
53+
throw new AssertionError("")
54+
}
5155
ctx.error(ex"missing type parameter(s) for $arg", arg.pos)
56+
}
5257
}
5358
for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate))
5459
ctx.error(

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

Lines changed: 1 addition & 0 deletions
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)