File tree 6 files changed +40
-6
lines changed 6 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -858,7 +858,7 @@ class Definitions {
858
858
lazy val TransientParamAnnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.constructorOnly" )
859
859
def TransientParamAnnot (implicit ctx : Context ): ClassSymbol = TransientParamAnnotType .symbol.asClass
860
860
lazy val CompileTimeOnlyAnnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.compileTimeOnly" )
861
- def CompileTimeOnlyParamAnnot (implicit ctx : Context ): ClassSymbol = CompileTimeOnlyAnnotType .symbol.asClass
861
+ def CompileTimeOnlyAnnot (implicit ctx : Context ): ClassSymbol = CompileTimeOnlyAnnotType .symbol.asClass
862
862
lazy val SwitchAnnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.switch" )
863
863
def SwitchAnnot (implicit ctx : Context ): ClassSymbol = SwitchAnnotType .symbol.asClass
864
864
lazy val ThrowsAnnotType : TypeRef = ctx.requiredClassRef(" scala.throws" )
Original file line number Diff line number Diff line change @@ -326,8 +326,18 @@ object Erasure {
326
326
}
327
327
328
328
private def checkNotErased (tree : Tree )(implicit ctx : Context ): tree.type = {
329
- if (isErased(tree) && ! ctx.mode.is(Mode .Type ))
330
- ctx.error(em " ${tree.symbol} is declared as erased, but is in fact used " , tree.sourcePos)
329
+ if (! ctx.mode.is(Mode .Type )) {
330
+ if (isErased(tree))
331
+ ctx.error(em " ${tree.symbol} is declared as erased, but is in fact used " , tree.sourcePos)
332
+ tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot ) match {
333
+ case Some (annot) =>
334
+ annot.tree match {
335
+ case Apply (_, Literal (msg) :: Nil ) => ctx.error(msg.stringValue, tree.sourcePos)
336
+ case _ => ctx.error(" Reference to member with @compileTimeOnly" , tree.sourcePos)
337
+ }
338
+ case _ => // OK
339
+ }
340
+ }
331
341
tree
332
342
}
333
343
Original file line number Diff line number Diff line change @@ -401,8 +401,8 @@ object Checking {
401
401
if (! sym.is(Deferred ))
402
402
fail(NativeMembersMayNotHaveImplementation (sym))
403
403
}
404
- if (sym.hasAnnotation(defn.CompileTimeOnlyParamAnnot ))
405
- ctx.migrationWarning(" `@compileTimeOnly(msg)` will be replaced by `scala.compiletime.error(msg)`" , sym.sourcePos)
404
+ if (sym.hasAnnotation(defn.CompileTimeOnlyAnnot ))
405
+ ctx.migrationWarning(" `@compileTimeOnly(msg)` should be replaced with `scala.compiletime.error(msg)`" , sym.sourcePos)
406
406
else if (sym.is(Deferred , butNot = Param ) && ! sym.isType && ! sym.isSelfSym) {
407
407
if (! sym.owner.isClass || sym.owner.is(Module ) || sym.owner.isAnonymousClass)
408
408
fail(OnlyClassesCanHaveDeclaredButUndefinedMembers (sym))
Original file line number Diff line number Diff line change @@ -172,7 +172,7 @@ class CompilationTests extends ParallelTesting {
172
172
" tests/neg-custom-args/toplevel-samesource/S.scala" ,
173
173
" tests/neg-custom-args/toplevel-samesource/nested/S.scala" ),
174
174
defaultOptions) +
175
- compileFile(" tests/neg-custom-args/i6300.scala" , allowDeepSubtypes)
175
+ compileFile(" tests/neg-custom-args/i6300.scala" , allowDeepSubtypes) +
176
176
compileFile(" tests/neg-custom-args/i6312.scala" , defaultOptions and " -Xfatal-warnings" and " -migration" )
177
177
}.checkExpectedErrors()
178
178
Original file line number Diff line number Diff line change
1
+ trait A {
2
+ @ scala.annotation.compileTimeOnly(" oops" ) def f : Int
3
+ }
4
+
5
+ class B extends A {
6
+ def f = 0
7
+ }
8
+
9
+ object App {
10
+ (new B ).f
11
+ (new B : A ).f // error
12
+ }
Original file line number Diff line number Diff line change
1
+ trait A {
2
+ inline def f : Int = scala.compiletime.error(" oops" )
3
+ }
4
+
5
+ class B extends A {
6
+ override def f = 0
7
+ }
8
+
9
+ object App {
10
+ (new B ).f
11
+ (new B : A ).f // error
12
+ }
You can’t perform that action at this time.
0 commit comments