Skip to content

Commit 92b1a6b

Browse files
authored
Merge pull request #138 from scala/backport-lts-3.3-22035
Backport "Do not lift annotation arguments" to 3.3 LTS
2 parents dae6ba9 + a08bf03 commit 92b1a6b

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

Diff for: compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
138138
def allTermArguments(tree: Tree): List[Tree] = unsplice(tree) match {
139139
case Apply(fn, args) => allTermArguments(fn) ::: args
140140
case TypeApply(fn, args) => allTermArguments(fn)
141-
case Block(_, expr) => allTermArguments(expr)
141+
case Block(Nil, expr) => allTermArguments(expr)
142142
case _ => Nil
143143
}
144144

145145
/** All type and term arguments of an application in a single flattened list */
146146
def allArguments(tree: Tree): List[Tree] = unsplice(tree) match {
147147
case Apply(fn, args) => allArguments(fn) ::: args
148148
case TypeApply(fn, args) => allArguments(fn) ::: args
149-
case Block(_, expr) => allArguments(expr)
149+
case Block(Nil, expr) => allArguments(expr)
150150
case _ => Nil
151151
}
152152

Diff for: compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
10391039
def recur(t: untpd.Tree): Text = t match
10401040
case Apply(fn, Nil) => recur(fn)
10411041
case Apply(fn, args) =>
1042-
val explicitArgs = args.filterNot(_.symbol.name.is(DefaultGetterName))
1042+
val explicitArgs = args.filterNot(untpd.stripNamedArg(_).symbol.name.is(DefaultGetterName))
10431043
recur(fn) ~ "(" ~ toTextGlobal(explicitArgs, ", ") ~ ")"
10441044
case TypeApply(fn, args) => recur(fn) ~ "[" ~ toTextGlobal(args, ", ") ~ "]"
10451045
case Select(qual, nme.CONSTRUCTOR) => recur(qual)

Diff for: compiler/src/dotty/tools/dotc/typer/Applications.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ trait Applications extends Compatibility {
459459
case tp => args.size
460460
}
461461

462-
!isJavaAnnotConstr(methRef.symbol) &&
462+
!isAnnotConstr(methRef.symbol) &&
463463
args.size < requiredArgNum(funType)
464464
}
465465

@@ -591,6 +591,11 @@ trait Applications extends Compatibility {
591591
def isJavaAnnotConstr(sym: Symbol): Boolean =
592592
sym.is(JavaDefined) && sym.isConstructor && sym.owner.is(JavaAnnotation)
593593

594+
595+
/** Is `sym` a constructor of an annotation? */
596+
def isAnnotConstr(sym: Symbol): Boolean =
597+
sym.isConstructor && sym.owner.isAnnotation
598+
594599
/** Match re-ordered arguments against formal parameters
595600
* @param n The position of the first parameter in formals in `methType`.
596601
*/

Diff for: tests/printing/dependent-annot-default-args.check

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[[syntax trees at end of typer]] // tests/printing/dependent-annot-default-args.scala
2+
package <empty> {
3+
class annot(x: Any, y: Any) extends annotation.Annotation() {
4+
private[this] val x: Any
5+
private[this] val y: Any
6+
}
7+
final lazy module val annot: annot = new annot()
8+
final module class annot() extends AnyRef() { this: annot.type =>
9+
def $lessinit$greater$default$2: Any @uncheckedVariance = 42
10+
}
11+
final lazy module val dependent-annot-default-args$package:
12+
dependent-annot-default-args$package =
13+
new dependent-annot-default-args$package()
14+
final module class dependent-annot-default-args$package() extends Object() {
15+
this: dependent-annot-default-args$package.type =>
16+
def f(x: Int): Int @annot(x) = x
17+
def test: Unit =
18+
{
19+
val y: Int = ???
20+
val z: Int @annot(y) = f(y)
21+
()
22+
}
23+
}
24+
}
25+

Diff for: tests/printing/dependent-annot-default-args.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class annot(x: Any, y: Any = 42) extends annotation.Annotation
2+
def f(x: Int): Int @annot(x) = x
3+
def test =
4+
val y: Int = ???
5+
val z = f(y)

0 commit comments

Comments
 (0)