Skip to content

Commit 84c90bf

Browse files
Merge pull request #6416 from dotty-staging/fix-#6312
Fix #6312: Add migration warning for @compileTimeOnly
2 parents 944b6b3 + 09f0093 commit 84c90bf

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,8 @@ class Definitions {
857857
def TailrecAnnot(implicit ctx: Context): ClassSymbol = TailrecAnnotType.symbol.asClass
858858
lazy val TransientParamAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.constructorOnly")
859859
def TransientParamAnnot(implicit ctx: Context): ClassSymbol = TransientParamAnnotType.symbol.asClass
860+
lazy val CompileTimeOnlyAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.compileTimeOnly")
861+
def CompileTimeOnlyParamAnnot(implicit ctx: Context): ClassSymbol = CompileTimeOnlyAnnotType.symbol.asClass
860862
lazy val SwitchAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.switch")
861863
def SwitchAnnot(implicit ctx: Context): ClassSymbol = SwitchAnnotType.symbol.asClass
862864
lazy val ThrowsAnnotType: TypeRef = ctx.requiredClassRef("scala.throws")

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ object Checking {
401401
if (!sym.is(Deferred))
402402
fail(NativeMembersMayNotHaveImplementation(sym))
403403
}
404+
if (sym.hasAnnotation(defn.CompileTimeOnlyParamAnnot))
405+
ctx.migrationWarning("`@compileTimeOnly(msg)` will be replaced by `scala.compiletime.error(msg)`", sym.sourcePos)
404406
else if (sym.is(Deferred, butNot = Param) && !sym.isType && !sym.isSelfSym) {
405407
if (!sym.owner.isClass || sym.owner.is(Module) || sym.owner.isAnonymousClass)
406408
fail(OnlyClassesCanHaveDeclaredButUndefinedMembers(sym))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class CompilationTests extends ParallelTesting {
173173
"tests/neg-custom-args/toplevel-samesource/nested/S.scala"),
174174
defaultOptions) +
175175
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes)
176+
compileFile("tests/neg-custom-args/i6312.scala", defaultOptions and "-Xfatal-warnings" and "-migration")
176177
}.checkExpectedErrors()
177178

178179
@Test def fuzzyAll: Unit = {

tests/neg-custom-args/i6312.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
inline def foo: Unit = {
3+
@scala.annotation.compileTimeOnly("some message") val res = ??? // error
4+
res
5+
}
6+
}

tests/neg/i6312.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
inline def foo: Unit = {
3+
scala.compiletime.error("some message")
4+
}
5+
foo // error: some message
6+
}

tests/pos/i6312.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo {
2+
inline def foo: Unit = {
3+
scala.compiletime.error("some message")
4+
}
5+
}

0 commit comments

Comments
 (0)