File tree 5 files changed +44
-5
lines changed
compiler/src/dotty/tools/dotc
5 files changed +44
-5
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,23 @@ 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
+ if (ctx.scala2Mode) {
335
+ // Scala 2 macros cannot be expanded for which we emit warnings. The best we can do is warn as well.
336
+ ctx.error(" Reference to member with @compileTimeOnly" , tree.sourcePos)
337
+ } else {
338
+ annot.tree match {
339
+ case Apply (_, Literal (msg) :: Nil ) => ctx.error(msg.stringValue, tree.sourcePos)
340
+ case _ => ctx.error(" Reference to member with @compileTimeOnly" , tree.sourcePos)
341
+ }
342
+ }
343
+ case _ => // OK
344
+ }
345
+ }
331
346
tree
332
347
}
333
348
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
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