Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not lift annotation arguments #22035

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
def allTermArguments(tree: Tree): List[Tree] = unsplice(tree) match {
case Apply(fn, args) => allTermArguments(fn) ::: args
case TypeApply(fn, args) => allTermArguments(fn)
case Block(_, expr) => allTermArguments(expr)
case Block(Nil, expr) => allTermArguments(expr)
case _ => Nil
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
def recur(t: untpd.Tree): Text = t match
case Apply(fn, Nil) => recur(fn)
case Apply(fn, args) =>
val explicitArgs = args.filterNot(_.symbol.name.is(DefaultGetterName))
val explicitArgs = args.filterNot(untpd.stripNamedArg(_).symbol.name.is(DefaultGetterName))
recur(fn) ~ "(" ~ toTextGlobal(explicitArgs, ", ") ~ ")"
case TypeApply(fn, args) => recur(fn) ~ "[" ~ toTextGlobal(args, ", ") ~ "]"
case Select(qual, nme.CONSTRUCTOR) => recur(qual)
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ trait Applications extends Compatibility {
case tp => args.size
}

!isJavaAnnotConstr(methRef.symbol) &&
!isAnnotConstr(methRef.symbol) &&
args.size < requiredArgNum(funType)
}

Expand Down Expand Up @@ -662,6 +662,11 @@ trait Applications extends Compatibility {
def isJavaAnnotConstr(sym: Symbol): Boolean =
sym.is(JavaDefined) && sym.isConstructor && sym.owner.is(JavaAnnotation)


/** Is `sym` a constructor of an annotation? */
def isAnnotConstr(sym: Symbol): Boolean =
sym.isConstructor && sym.owner.isAnnotation

/** Match re-ordered arguments against formal parameters
* @param n The position of the first parameter in formals in `methType`.
*/
Expand Down
25 changes: 25 additions & 0 deletions tests/printing/dependent-annot-default-args.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[[syntax trees at end of typer]] // tests/printing/dependent-annot-default-args.scala
package <empty> {
class annot(x: Any, y: Any) extends annotation.Annotation() {
private[this] val x: Any
private[this] val y: Any
}
final lazy module val annot: annot = new annot()
final module class annot() extends AnyRef() { this: annot.type =>
def $lessinit$greater$default$2: Any @uncheckedVariance = 42
}
final lazy module val dependent-annot-default-args$package:
dependent-annot-default-args$package =
new dependent-annot-default-args$package()
final module class dependent-annot-default-args$package() extends Object() {
this: dependent-annot-default-args$package.type =>
def f(x: Int): Int @annot(x) = x
def test: Unit =
{
val y: Int = ???
val z: Int @annot(y) = f(y)
()
}
}
}

5 changes: 5 additions & 0 deletions tests/printing/dependent-annot-default-args.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class annot(x: Any, y: Any = 42) extends annotation.Annotation
def f(x: Int): Int @annot(x) = x
def test =
val y: Int = ???
val z = f(y)
Loading