File tree 4 files changed +38
-0
lines changed
compiler/src/dotty/tools/dotc
library/src/scala/annotation 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -790,6 +790,8 @@ class Definitions {
790
790
def TASTYLongSignatureAnnot (implicit ctx : Context ): ClassSymbol = TASTYLongSignatureAnnotType .symbol.asClass
791
791
lazy val TailrecAnnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.tailrec" )
792
792
def TailrecAnnot (implicit ctx : Context ): ClassSymbol = TailrecAnnotType .symbol.asClass
793
+ lazy val TransientParamAnnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.transientParam" )
794
+ def TransientParamAnnot (implicit ctx : Context ): ClassSymbol = TransientParamAnnotType .symbol.asClass
793
795
lazy val SwitchAnnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.switch" )
794
796
def SwitchAnnot (implicit ctx : Context ): ClassSymbol = SwitchAnnotType .symbol.asClass
795
797
lazy val ThrowsAnnotType : TypeRef = ctx.requiredClassRef(" scala.throws" )
Original file line number Diff line number Diff line change @@ -224,6 +224,8 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
224
224
dropped += acc
225
225
Nil
226
226
} else {
227
+ if (acc.hasAnnotation(defn.TransientParamAnnot ))
228
+ ctx.error(em " transient parameter $acc is retained as field in class ${acc.owner}" , acc.pos)
227
229
val target = if (acc.is(Method )) acc.field else acc
228
230
if (! target.exists) Nil // this case arises when the parameter accessor is an alias
229
231
else {
Original file line number Diff line number Diff line change
1
+ /* __ *\
2
+ ** ________ ___ / / ___ Scala API **
3
+ ** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
4
+ ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5
+ ** /____/\___/_/ |_/____/_/ | | **
6
+ ** |/ **
7
+ \* */
8
+
9
+ package scala .annotation
10
+
11
+ import scala .annotation .meta ._
12
+
13
+ /** An annotation that goes on parameters of classes or traits. It asserts
14
+ * that the parameter is used only for initialization and is not kept in
15
+ * the class as a field. Violations of this assertion are flagged as
16
+ * compile errors. The annotatoon is particularly useful for implicit
17
+ * parameters since for these a textual scan is not sufficient to know
18
+ * where they are used.
19
+ */
20
+ @ param class transientParam extends scala.annotation.StaticAnnotation
Original file line number Diff line number Diff line change
1
+ import annotation .transientParam
2
+ class Context
3
+
4
+ class Test1 ()(implicit @ transientParam ctx : Context ) { // error
5
+ def test1 = implicitly[Context ]
6
+ }
7
+
8
+ class Test2 ()(@ transientParam ctx : Context ) { // error
9
+ def test1 = ctx
10
+ }
11
+
12
+ class Test3 ()(implicit @ transientParam ctx : Context ) { // OK
13
+ val foo = implicitly[Context ]
14
+ }
You can’t perform that action at this time.
0 commit comments