Skip to content

Commit d05cccc

Browse files
authored
Merge pull request #10093 from dotty-staging/change-alpha
Keep @Alpha optional
2 parents 4bb1004 + 3a79a78 commit d05cccc

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +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")
175176

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

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,17 @@ object Checking {
311311
/** If `sym` has an operator name, check that it has an @alpha annotation in 3.1 and later
312312
*/
313313
def checkValidOperator(sym: Symbol)(using Context): Unit =
314-
sym.name.toTermName match {
315-
case name: SimpleName
316-
if name.isOperatorName
317-
&& !name.isSetterName
318-
&& !name.isConstructorName
319-
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
320-
&& !sym.is(Synthetic)
321-
&& sourceVersion.isAtLeast(`3.1`) =>
322-
report.deprecationWarning(
323-
i"$sym has an operator name; it should come with an @alpha annotation", sym.srcPos)
324-
case _ =>
325-
}
314+
if ctx.settings.YrequireAlpha.value then
315+
sym.name.toTermName match
316+
case name: SimpleName
317+
if name.isOperatorName
318+
&& !name.isSetterName
319+
&& !name.isConstructorName
320+
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
321+
&& !sym.is(Synthetic) =>
322+
report.warning(
323+
i"$sym has an operator name; it should come with an @alpha annotation", sym.srcPos)
324+
case _ =>
326325

327326
/** Check that `info` of symbol `sym` is not cyclic.
328327
* @pre sym is not yet initialized (i.e. its type is a Completer).

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("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
156+
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-Yrequire-alpha", "-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")),

docs/docs/reference/changed-features/operators.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ VecOps.append(vec1, vec2)
2222
```
2323
The `@alpha` annotation has no bearing on Scala usages. Any application of that method in Scala has to use `++=`, not `append`.
2424

25-
An `@alpha` annotation will be _mandatory_ if the method name is symbolic. Symbolic methods without `@alpha` annotations are deprecated.
26-
2725
### Motivation
2826

2927
The `@alpha` annotation serves a dual purpose:

0 commit comments

Comments
 (0)