diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 15bf66caa6bd..2bc6c26d0ab3 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -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") diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 92d8fedd7516..5bea0e84f050 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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)) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index b275459485c4..898697833765 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -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 = { diff --git a/tests/neg-custom-args/i6312.scala b/tests/neg-custom-args/i6312.scala new file mode 100644 index 000000000000..c80e5c246a00 --- /dev/null +++ b/tests/neg-custom-args/i6312.scala @@ -0,0 +1,6 @@ +class Foo { + inline def foo: Unit = { + @scala.annotation.compileTimeOnly("some message") val res = ??? // error + res + } +} diff --git a/tests/neg/i6312.scala b/tests/neg/i6312.scala new file mode 100644 index 000000000000..20d4876d3f11 --- /dev/null +++ b/tests/neg/i6312.scala @@ -0,0 +1,6 @@ +class Foo { + inline def foo: Unit = { + scala.compiletime.error("some message") + } + foo // error: some message +} diff --git a/tests/pos/i6312.scala b/tests/pos/i6312.scala new file mode 100644 index 000000000000..defeaa56554c --- /dev/null +++ b/tests/pos/i6312.scala @@ -0,0 +1,5 @@ +class Foo { + inline def foo: Unit = { + scala.compiletime.error("some message") + } +}