File tree 6 files changed +45
-15
lines changed
compiler/src/dotty/tools/dotc 6 files changed +45
-15
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,26 @@ 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
+ def defaultMsg =
335
+ s """ Reference to ${tree.symbol.showLocated} should not have survived,
336
+ |it should have been processed and eliminated during expansion of an enclosing macro or term erasure. """
337
+ if (ctx.scala2Mode) {
338
+ // Scala 2 macros cannot be expanded for which we emit warnings. The best we can do is warn as well.
339
+ ctx.warning(defaultMsg, tree.sourcePos)
340
+ } else {
341
+ annot.tree match {
342
+ case Apply (_, Literal (msg) :: Nil ) => ctx.error(msg.stringValue, tree.sourcePos)
343
+ case _ => ctx.error(defaultMsg, tree.sourcePos)
344
+ }
345
+ }
346
+ case _ => // OK
347
+ }
348
+ }
331
349
tree
332
350
}
333
351
Original file line number Diff line number Diff line change @@ -401,8 +401,6 @@ 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)
406
404
else if (sym.is(Deferred , butNot = Param ) && ! sym.isType && ! sym.isSelfSym) {
407
405
if (! sym.owner.isClass || sym.owner.is(Module ) || sym.owner.isAnonymousClass)
408
406
fail(OnlyClassesCanHaveDeclaredButUndefinedMembers (sym))
Original file line number Diff line number Diff line change @@ -822,16 +822,6 @@ object RefChecks {
822
822
case _ =>
823
823
}
824
824
}
825
- /* (Not enabled yet)
826
- * See an explanation of compileTimeOnly in its scaladoc at scala.annotation.compileTimeOnly.
827
- *
828
- if (sym.isCompileTimeOnly) {
829
- def defaultMsg =
830
- sm"""Reference to ${sym.fullLocationString} should not have survived past type checking,
831
- |it should have been processed and eliminated during expansion of an enclosing macro."""
832
- // The getOrElse part should never happen, it's just here as a backstop.
833
- ctx.error(sym.compileTimeOnlyMessage getOrElse defaultMsg, pos)
834
- }*/
835
825
}
836
826
837
827
/** Check that a deprecated val or def does not override a
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