Skip to content

Fix #6312: Add migration warning for @compileTimeOnly #6416

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 2 commits into from
May 2, 2019
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ class Definitions {
def TailrecAnnot(implicit ctx: Context): ClassSymbol = TailrecAnnotType.symbol.asClass
lazy val TransientParamAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.constructorOnly")
def TransientParamAnnot(implicit ctx: Context): ClassSymbol = TransientParamAnnotType.symbol.asClass
lazy val CompileTimeOnlyAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.compileTimeOnly")
def CompileTimeOnlyParamAnnot(implicit ctx: Context): ClassSymbol = CompileTimeOnlyAnnotType.symbol.asClass
lazy val SwitchAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.switch")
def SwitchAnnot(implicit ctx: Context): ClassSymbol = SwitchAnnotType.symbol.asClass
lazy val ThrowsAnnotType: TypeRef = ctx.requiredClassRef("scala.throws")
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ object Checking {
if (!sym.is(Deferred))
fail(NativeMembersMayNotHaveImplementation(sym))
}
if (sym.hasAnnotation(defn.CompileTimeOnlyParamAnnot))
ctx.migrationWarning("`@compileTimeOnly(msg)` will be replaced by `scala.compiletime.error(msg)`", sym.sourcePos)
else if (sym.is(Deferred, butNot = Param) && !sym.isType && !sym.isSelfSym) {
if (!sym.owner.isClass || sym.owner.is(Module) || sym.owner.isAnonymousClass)
fail(OnlyClassesCanHaveDeclaredButUndefinedMembers(sym))
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class CompilationTests extends ParallelTesting {
"tests/neg-custom-args/toplevel-samesource/nested/S.scala"),
defaultOptions) +
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes)
compileFile("tests/neg-custom-args/i6312.scala", defaultOptions and "-Xfatal-warnings" and "-migration")
}.checkExpectedErrors()

@Test def fuzzyAll: Unit = {
Expand Down
6 changes: 6 additions & 0 deletions tests/neg-custom-args/i6312.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo {
inline def foo: Unit = {
@scala.annotation.compileTimeOnly("some message") val res = ??? // error
res
}
}
6 changes: 6 additions & 0 deletions tests/neg/i6312.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo {
inline def foo: Unit = {
scala.compiletime.error("some message")
}
foo // error: some message
}
5 changes: 5 additions & 0 deletions tests/pos/i6312.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
inline def foo: Unit = {
scala.compiletime.error("some message")
}
}