Skip to content

Commit a25fe65

Browse files
committed
Rename @Alpha to @TargetNAME
1 parent 1ab76c1 commit a25fe65

File tree

27 files changed

+81
-79
lines changed

27 files changed

+81
-79
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ScalaSettings extends Settings.SettingGroup {
172172
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
173173
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "Allows the use of erased terms.")
174174
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ycheck-init", "Check initialization of objects")
175-
val YrequireAlpha: Setting[Boolean] = BooleanSetting("-Yrequire-alpha", "Warn if an operator is defined without an @alpha annotation")
175+
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
176176

177177
/** Area-specific debug output */
178178
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ class Definitions {
948948
@tu lazy val ShowAsInfixAnnot: ClassSymbol = requiredClass("scala.annotation.showAsInfix")
949949
@tu lazy val FunctionalInterfaceAnnot: ClassSymbol = requiredClass("java.lang.FunctionalInterface")
950950
@tu lazy val InfixAnnot: ClassSymbol = requiredClass("scala.annotation.infix")
951-
@tu lazy val AlphaAnnot: ClassSymbol = requiredClass("scala.annotation.alpha")
951+
@tu lazy val TargetNameAnnot: ClassSymbol = requiredClass("scala.annotation.targetName")
952952
@tu lazy val VarargsAnnot: ClassSymbol = requiredClass("scala.annotation.varargs")
953953

954954
// A list of annotations that are commonly used to indicate that a field/method argument or return

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,26 +493,21 @@ object SymDenotations {
493493
/** `fullName` where `.' is the separator character */
494494
def fullName(using Context): Name = fullNameSeparated(QualifiedName)
495495

496-
/** The name given in an `@alpha` annotation if one is present, `name` otherwise */
496+
/** The name given in a `@targetName` annotation if one is present, `name` otherwise */
497497
final def erasedName(using Context): Name =
498-
val alphaAnnot =
499-
if isAllOf(ModuleClass | Synthetic) then companionClass.getAnnotation(defn.AlphaAnnot)
500-
else getAnnotation(defn.AlphaAnnot)
501-
alphaAnnot match {
498+
val targetNameAnnot =
499+
if isAllOf(ModuleClass | Synthetic) then companionClass.getAnnotation(defn.TargetNameAnnot)
500+
else getAnnotation(defn.TargetNameAnnot)
501+
targetNameAnnot match
502502
case Some(ann) =>
503-
ann.arguments match {
503+
ann.arguments match
504504
case Literal(Constant(str: String)) :: Nil =>
505-
if (isType)
506-
if (is(ModuleClass))
507-
str.toTypeName.moduleClassName
508-
else
509-
str.toTypeName
510-
else
511-
str.toTermName
505+
if isType then
506+
if is(ModuleClass) then str.toTypeName.moduleClassName
507+
else str.toTypeName
508+
else str.toTermName
512509
case _ => name
513-
}
514510
case _ => name
515-
}
516511

517512
// ----- Tests -------------------------------------------------
518513

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,20 @@ object Checking {
308308
}
309309
}
310310

311-
/** If `sym` has an operator name, check that it has an @alpha annotation in 3.1 and later
311+
/** Under -Yrequire-targetName, if `sym` has an operator name, check that it has a
312+
* @targetName annotation.
312313
*/
313314
def checkValidOperator(sym: Symbol)(using Context): Unit =
314-
if ctx.settings.YrequireAlpha.value then
315+
if ctx.settings.YrequireTargetName.value then
315316
sym.name.toTermName match
316317
case name: SimpleName
317318
if name.isOperatorName
318319
&& !name.isSetterName
319320
&& !name.isConstructorName
320-
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
321+
&& !sym.getAnnotation(defn.TargetNameAnnot).isDefined
321322
&& !sym.is(Synthetic) =>
322323
report.warning(
323-
i"$sym has an operator name; it should come with an @alpha annotation", sym.srcPos)
324+
i"$sym has an operator name; it should come with an @targetName annotation", sym.srcPos)
324325
case _ =>
325326

326327
/** Check that `info` of symbol `sym` is not cyclic.
@@ -1203,19 +1204,16 @@ trait Checking {
12031204
}
12041205

12051206
/** Check that symbol's external name does not clash with symbols defined in the same scope */
1206-
def checkNoAlphaConflict(stats: List[Tree])(using Context): Unit = {
1207+
def checkNoTargetNameConflict(stats: List[Tree])(using Context): Unit =
12071208
var seen = Set[Name]()
1208-
for (stat <- stats) {
1209+
for stat <- stats do
12091210
val sym = stat.symbol
12101211
val ename = sym.erasedName
1211-
if (ename != sym.name) {
1212+
if ename != sym.name then
12121213
val preExisting = ctx.effectiveScope.lookup(ename)
1213-
if (preExisting.exists || seen.contains(ename))
1214-
report.error(em"@alpha annotation ${'"'}$ename${'"'} clashes with other definition is same scope", stat.srcPos)
1214+
if preExisting.exists || seen.contains(ename) then
1215+
report.error(em"@targetName annotation ${'"'}$ename${'"'} clashes with other definition in same scope", stat.srcPos)
12151216
if stat.isDef then seen += ename
1216-
}
1217-
}
1218-
}
12191217
}
12201218

12211219
trait ReChecking extends Checking {
@@ -1238,7 +1236,7 @@ trait NoChecking extends ReChecking {
12381236
override def checkImplicitConversionUseOK(tree: Tree)(using Context): Unit = ()
12391237
override def checkFeasibleParent(tp: Type, pos: SrcPos, where: => String = "")(using Context): Type = tp
12401238
override def checkInlineConformant(tpt: Tree, tree: Tree, sym: Symbol)(using Context): Unit = ()
1241-
override def checkNoAlphaConflict(stats: List[Tree])(using Context): Unit = ()
1239+
override def checkNoTargetNameConflict(stats: List[Tree])(using Context): Unit = ()
12421240
override def checkParentCall(call: Tree, caller: ClassSymbol)(using Context): Unit = ()
12431241
override def checkSimpleKinded(tpt: Tree)(using Context): Tree = tpt
12441242
override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(using Context): Unit = ()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ object RefChecks {
433433
overrideError("has incompatible type" + err.whyNoMatchStr(memberTp(self), otherTp(self)))
434434
else if (member.erasedName != other.erasedName)
435435
if (other.erasedName != other.name)
436-
overrideError(i"needs to be declared with @alpha(${"\""}${other.erasedName}${"\""}) so that external names match")
436+
overrideError(i"needs to be declared with @targetName(${"\""}${other.erasedName}${"\""}) so that external names match")
437437
else
438-
overrideError("cannot have an @alpha annotation since external names would be different")
438+
overrideError("cannot have a @targetName annotation since external names would be different")
439439
else
440440
checkOverrideDeprecated()
441441
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ class Typer extends Namer
19881988
if (sym.isConstructor && !sym.isPrimaryConstructor) {
19891989
val ename = sym.erasedName
19901990
if (ename != sym.name)
1991-
report.error(em"@alpha annotation ${'"'}$ename${'"'} may not be used on a constructor", ddef.srcPos)
1991+
report.error(em"@targetName annotation may not be used on a constructor", ddef.srcPos)
19921992

19931993
for (param <- tparams1 ::: vparamss1.flatten)
19941994
checkRefsLegal(param, sym.owner, (name, sym) => sym.is(TypeParam), "secondary constructor")
@@ -2663,7 +2663,7 @@ class Typer extends Namer
26632663
}
26642664
val (stats0, finalCtx) = traverse(stats)(using localCtx)
26652665
val stats1 = stats0.mapConserve(finalize)
2666-
if (ctx.owner == exprOwner) checkNoAlphaConflict(stats1)
2666+
if ctx.owner == exprOwner then checkNoTargetNameConflict(stats1)
26672667
(stats1, finalCtx)
26682668
}
26692669

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class CompilationTests {
153153
defaultOptions),
154154
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes),
155155
compileFile("tests/neg-custom-args/infix.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
156-
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-Yrequire-alpha", "-Xfatal-warnings")),
156+
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-Yrequire-targetName", "-Xfatal-warnings")),
157157
compileFile("tests/neg-custom-args/wildcards.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
158158
compileFile("tests/neg-custom-args/indentRight.scala", defaultOptions.and("-noindent", "-Xfatal-warnings")),
159159
compileFile("tests/neg-custom-args/extmethods-tparams.scala", defaultOptions.and("-deprecation", "-Xfatal-warnings")),

library/src/scala/annotation/alpha.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ package scala.annotation
66
* the regular name. An `alpha` annotation is mandatory for definitions
77
* with symbolic names.
88
*/
9+
@deprecated("use @targetName instead")
910
final class alpha(externalName: String) extends StaticAnnotation
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.annotation
2+
3+
/** An annotation that defines an external name for a definition.
4+
* If an `targetName(extname)` annotation is given for a method or some other
5+
* definition, its implementation will use the name `extname` instead of
6+
* the regular name.
7+
*/
8+
final class targetName(name: String) extends StaticAnnotation

tests/neg-custom-args/missing-alpha.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Compile with -strict -Xfatal-warnings -deprecation
2-
import scala.annotation.alpha
2+
import scala.annotation.targetName
33
class & { // error
44

5-
@alpha("op") def *(x: Int): Int = ??? // OK
5+
@targetName("op") def *(x: Int): Int = ??? // OK
66
def / (x: Int): Int // error
77
val frozen_& : Int = ??? // error
88
object some_??? // error

tests/neg/7722.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Error: tests/neg/7722.scala:2:35 ------------------------------------------------------------------------------------
2-
2 | @scala.annotation.alpha("E") def this() = this(3) // error
3-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| @alpha annotation "E" may not be used on a constructor
1+
-- Error: tests/neg/7722.scala:2:40 ------------------------------------------------------------------------------------
2+
2 | @scala.annotation.targetName("E") def this() = this(3) // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| @targetName annotation may not be used on a constructor

tests/neg/7722.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class A(i:Int){
2-
@scala.annotation.alpha("E") def this() = this(3) // error
2+
@scala.annotation.targetName("E") def this() = this(3) // error
33
}
44
object O{
55
def main(args: Array[String]) = {

tests/neg/alpha-early.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
import annotation.alpha
2+
import annotation.targetName
33

44
class Gamma {
55

66
def foo2() = {
77
def bar = 1
8-
@alpha("bar") def baz = 2 // error: @alpha annotation clashes
8+
@targetName("bar") def baz = 2 // error: @targetName annotation clashes
99

10-
@alpha("bam") def x1 = 0
11-
@alpha("bam") def y1 = 0 // error: @alpha annotation clashes
10+
@targetName("bam") def x1 = 0
11+
@targetName("bam") def y1 = 0 // error: @targetName annotation clashes
1212

1313
}
1414
}

tests/neg/alpha-late.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import annotation.alpha
2+
import annotation.targetName
33

44
class Gamma {
55

@@ -8,5 +8,5 @@ class Gamma {
88
}
99

1010
class Delta extends Gamma { // error: name clash
11-
@alpha("foo") def bar: Int = 1
11+
@targetName("foo") def bar: Int = 1
1212
}

tests/neg/alpha-override/C_2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import annotation.alpha
1+
import annotation.targetName
22
class C extends B_1 { // error: Name clash between defined and inherited member
3-
@alpha("bar") def foo(): Int = 3
3+
@targetName("bar") def foo(): Int = 3
44
}

tests/neg/alpha-override1/D_2.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import annotation.alpha
1+
import annotation.targetName
22
class D extends B_1 {
3-
@alpha("bar") def foo(): Int = 3
3+
@targetName("bar") def foo(): Int = 3
44
}
55
class E extends B_1 {
6-
@alpha("baz") override def bar(): Int = 3 // error: cannot have an @alpha annotation since external names would be different
6+
@targetName("baz") override def bar(): Int = 3 // error: cannot have an @targetName annotation since external names would be different
77
}

tests/neg/alpha.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import annotation.alpha
1+
import annotation.targetName
22

33

44
abstract class Alpha[T] {
55

66
def foo() = 1
77

8-
@alpha("bar") def foo(x: T): T
8+
@targetName("bar") def foo(x: T): T
99

10-
@alpha("append") def ++ (xs: Alpha[T]): Alpha[T] = this
10+
@targetName("append") def ++ (xs: Alpha[T]): Alpha[T] = this
1111

1212
}
1313

1414
class Beta extends Alpha[String] {
1515

16-
@alpha("foo1") override def foo() = 1 // error
16+
@targetName("foo1") override def foo() = 1 // error
1717

18-
@alpha("baz") def foo(x: String): String = x ++ x // error
18+
@targetName("baz") def foo(x: String): String = x ++ x // error
1919

2020
override def ++ (xs: Alpha[String]): Alpha[String] = this // error
2121

tests/neg/doubleDefinition-late.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
import annotation.alpha
2+
import annotation.targetName
33

44
class Gamma {
55

66
val v = 1
7-
@alpha("v") val w = 2 // error: double definition
7+
@targetName("v") val w = 2 // error: double definition
88

99
}
1010
// Error when overloading polymorphic and non-polymorphic methods

tests/pos/alpha-override/A_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Scala
2-
import annotation.alpha
2+
import annotation.targetName
33
class A_1 {
4-
@alpha("bar") def foo(): Int = 1
4+
@targetName("bar") def foo(): Int = 1
55
}

tests/pos/alpha.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import annotation.alpha
1+
import annotation.targetName
22

33
object Test {
44

55
def foo() = 1
66

7-
@alpha("bar") def foo(x: Int) = 2
7+
@targetName("bar") def foo(x: Int) = 2
88
}

tests/pos/i8391.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import scala.annotation.alpha
1+
import scala.annotation.targetName
22

33
trait Foo {
4-
@alpha("intersection")
4+
@targetName("intersection")
55
def *(other: Foo): Foo
66
}
77

tests/run/alpha-interop/alpha_1.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package alpha
2-
import annotation.alpha
2+
import annotation.targetName
33

44
abstract class Alpha[T] {
55

66
def foo() = 1
77

8-
@alpha("bar") def foo(x: T): T
8+
@targetName("bar") def foo(x: T): T
99

10-
@alpha("append") def ++ (xs: Alpha[T]): Alpha[T] = this
10+
@targetName("append") def ++ (xs: Alpha[T]): Alpha[T] = this
1111

1212
}
1313

14-
@alpha("Bar") class | extends Alpha[String] {
14+
@targetName("Bar") class | extends Alpha[String] {
1515

16-
@alpha("bar") override def foo(x: String) = x ++ x
16+
@targetName("bar") override def foo(x: String) = x ++ x
1717

18-
@alpha("append") override def ++ (xs: Alpha[String]) = this
18+
@targetName("append") override def ++ (xs: Alpha[String]) = this
1919

2020
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package alpha
22

3-
@scala.annotation.alpha("A") object B {
3+
@scala.annotation.targetName("A") object B {
44
def foo = 23
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package alpha
22

3-
@scala.annotation.alpha("A") class B(val i: Int = 1)
3+
@scala.annotation.targetName("A") class B(val i: Int = 1)

tests/run/alpha.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import annotation.alpha
1+
import annotation.targetName
22

33
object Test extends App {
44
def foo(x: Any): Int = 1
5-
@alpha("bar") def foo[A <: AnyRef](x: A) = 2
5+
@targetName("bar") def foo[A <: AnyRef](x: A) = 2
66

77
assert(foo("a") == 2)
88
}

tests/run/i9155.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Foo:
2-
@scala.annotation.alpha("w") def \/\/ = "W"
2+
@scala.annotation.targetName("w") def \/\/ = "W"
33

44
object Bar:
55
export Foo._

tests/run/infix.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import annotation.{infix, alpha}
1+
import annotation.{infix, targetName}
22
object Test extends App {
33

44
case class Rational(n: Int, d: Int) {
55
@infix def + (that: Rational) =
66
Rational(this.n * that.d + that.n * this.d, this.d * that.d)
7-
@infix @alpha("multiply") def * (that: Rational) =
7+
@infix @targetName("multiply") def * (that: Rational) =
88
Rational(this.n * that.n, this.d * that.d)
99
}
1010

0 commit comments

Comments
 (0)