Skip to content

Keep @alpha optional #10093

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

Merged
merged 1 commit into from
Oct 28, 2020
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class ScalaSettings extends Settings.SettingGroup {
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "Allows the use of erased terms.")
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ycheck-init", "Check initialization of objects")
val YrequireAlpha: Setting[Boolean] = BooleanSetting("-Yrequire-alpha", "Warn if an operator is defined without an @alpha annotation")

/** Area-specific debug output */
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
Expand Down
23 changes: 11 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,17 @@ object Checking {
/** If `sym` has an operator name, check that it has an @alpha annotation in 3.1 and later
*/
def checkValidOperator(sym: Symbol)(using Context): Unit =
sym.name.toTermName match {
case name: SimpleName
if name.isOperatorName
&& !name.isSetterName
&& !name.isConstructorName
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
&& !sym.is(Synthetic)
&& sourceVersion.isAtLeast(`3.1`) =>
report.deprecationWarning(
i"$sym has an operator name; it should come with an @alpha annotation", sym.srcPos)
case _ =>
}
if ctx.settings.YrequireAlpha.value then
sym.name.toTermName match
case name: SimpleName
if name.isOperatorName
&& !name.isSetterName
&& !name.isConstructorName
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
&& !sym.is(Synthetic) =>
report.warning(
i"$sym has an operator name; it should come with an @alpha annotation", sym.srcPos)
case _ =>

/** Check that `info` of symbol `sym` is not cyclic.
* @pre sym is not yet initialized (i.e. its type is a Completer).
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class CompilationTests {
defaultOptions),
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/infix.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-Yrequire-alpha", "-Xfatal-warnings")),
compileFile("tests/neg-custom-args/wildcards.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
compileFile("tests/neg-custom-args/indentRight.scala", defaultOptions.and("-noindent", "-Xfatal-warnings")),
compileFile("tests/neg-custom-args/extmethods-tparams.scala", defaultOptions.and("-deprecation", "-Xfatal-warnings")),
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/reference/changed-features/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ VecOps.append(vec1, vec2)
```
The `@alpha` annotation has no bearing on Scala usages. Any application of that method in Scala has to use `++=`, not `append`.

An `@alpha` annotation will be _mandatory_ if the method name is symbolic. Symbolic methods without `@alpha` annotations are deprecated.

### Motivation

The `@alpha` annotation serves a dual purpose:
Expand Down