Skip to content

Commit fbd15a7

Browse files
committed
Add handling of parsed annotations to applyOverloaded.
see annot.scala for examples
1 parent 68407fa commit fbd15a7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
679679
}
680680
}
681681

682-
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type)(implicit ctx: Context): Tree = {
682+
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type, isAnnotConstructor: Boolean = false)(implicit ctx: Context): Tree = {
683683
val typer = ctx.typer
684684
val proto = new FunProtoTyped(args, expectedType, typer)
685685
val alts = receiver.tpe.member(method).alternatives.map(_.termRef)
@@ -691,9 +691,29 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
691691
val fun = receiver
692692
.select(TermRef.withSig(receiver.tpe.normalizedPrefix, selected.termSymbol.asTerm))
693693
.appliedToTypes(targs)
694-
val apply = untpd.Apply(fun, args)
695694

696-
new typer.ApplyToTyped(apply, fun, selected, args, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
695+
val callArgs: List[Tree] = if(args.isEmpty) Nil else {
696+
val lastParamType = selected.widen.paramTypess.head.last
697+
val lastParam = args.last
698+
if (isAnnotConstructor && !(lastParam.tpe <:< lastParamType)) {
699+
val defn = ctx.definitions
700+
val prefix = args.take(selected.widen.paramTypess.head.size - 1)
701+
lastParamType match {
702+
case defn.ArrayType(el) =>
703+
lastParam.tpe match {
704+
case defn.ArrayType(el2) if (el2 <:< el) => // we have a JavaSeqLiteral with a more precise type
705+
prefix ::: List(tpd.Typed(lastParam, TypeTree(defn.ArrayType(el))))
706+
case _ =>
707+
???
708+
}
709+
//case defn.ArrayType(el) if(lastParam)
710+
case _ => args
711+
}
712+
} else args
713+
}
714+
715+
val apply = untpd.Apply(fun, callArgs)
716+
new typer.ApplyToTyped(apply, fun, selected, callArgs, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
697717
}
698718

699719
@tailrec

src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object Annotations {
6666

6767
private def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
6868
val targs = atp.argTypes
69-
tpd.applyOverloaded(New(atp withoutArgs targs), nme.CONSTRUCTOR, args, targs, atp)
69+
tpd.applyOverloaded(New(atp withoutArgs targs), nme.CONSTRUCTOR, args, targs, atp, isAnnotConstructor = true)
7070
}
7171

7272
def applyResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = {

0 commit comments

Comments
 (0)