Skip to content

Commit 9fa170c

Browse files
committed
Rename transientParam -> constructorOnly
1 parent 829acf0 commit 9fa170c

File tree

12 files changed

+133
-133
lines changed

12 files changed

+133
-133
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import util.{Property, SourceFile}
1212
import collection.mutable.ListBuffer
1313
import reporting.diagnostic.messages._
1414
import reporting.trace
15-
import annotation.transientParam
15+
import annotation.constructorOnly
1616

1717
import scala.annotation.internal.sharable
1818

@@ -43,23 +43,23 @@ object desugar {
4343

4444
// ----- DerivedTypeTrees -----------------------------------
4545

46-
class SetterParamTree(implicit @transientParam src: SourceFile) extends DerivedTypeTree {
46+
class SetterParamTree(implicit @constructorOnly src: SourceFile) extends DerivedTypeTree {
4747
def derivedTree(sym: Symbol)(implicit ctx: Context): tpd.TypeTree = tpd.TypeTree(sym.info.resultType)
4848
}
4949

50-
class TypeRefTree(implicit @transientParam src: SourceFile) extends DerivedTypeTree {
50+
class TypeRefTree(implicit @constructorOnly src: SourceFile) extends DerivedTypeTree {
5151
def derivedTree(sym: Symbol)(implicit ctx: Context): tpd.TypeTree = tpd.TypeTree(sym.typeRef)
5252
}
5353

54-
class TermRefTree(implicit @transientParam src: SourceFile) extends DerivedTypeTree {
54+
class TermRefTree(implicit @constructorOnly src: SourceFile) extends DerivedTypeTree {
5555
def derivedTree(sym: Symbol)(implicit ctx: Context): tpd.Tree = tpd.ref(sym)
5656
}
5757

5858
/** A type tree that computes its type from an existing parameter.
5959
* @param suffix String difference between existing parameter (call it `P`) and parameter owning the
6060
* DerivedTypeTree (call it `O`). We have: `O.name == P.name + suffix`.
6161
*/
62-
class DerivedFromParamTree(suffix: String)(implicit @transientParam src: SourceFile) extends DerivedTypeTree {
62+
class DerivedFromParamTree(suffix: String)(implicit @constructorOnly src: SourceFile) extends DerivedTypeTree {
6363

6464
/** Make sure that for all enclosing module classes their companion classes
6565
* are completed. Reason: We need the constructor of such companion classes to
@@ -1393,6 +1393,6 @@ object desugar {
13931393
buf.toList
13941394
}
13951395

1396-
private class IrrefutableGenFrom(pat: Tree, expr: Tree)(implicit @transientParam src: SourceFile)
1396+
private class IrrefutableGenFrom(pat: Tree, expr: Tree)(implicit @constructorOnly src: SourceFile)
13971397
extends GenFrom(pat, expr)
13981398
}

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import core.Contexts.Context
88
import core.Decorators._
99
import core.Flags.{JavaDefined, Extension}
1010
import core.StdNames.nme
11-
import annotation.transientParam
11+
import annotation.constructorOnly
1212
import annotation.internal.sharable
1313

1414
/** A base class for things that have positions (currently: modifiers and trees)
1515
*/
16-
abstract class Positioned(implicit @transientParam src: SourceFile) extends Product with Cloneable {
16+
abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Product with Cloneable {
1717

1818
private[this] var myUniqueId: Int = _
1919
private[this] var mySpan: Span = _

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 59 additions & 59 deletions
Large diffs are not rendered by default.

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import Types._, Contexts._, Constants._, Names._, Flags._
77
import Symbols._, StdNames._, Trees._
88
import util.{Property, SourceFile, NoSource}
99
import language.higherKinds
10-
import annotation.transientParam
10+
import annotation.constructorOnly
1111
import annotation.internal.sharable
1212

1313
object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
1414

1515
// ----- Tree cases that exist in untyped form only ------------------
1616

17-
abstract class OpTree(implicit @transientParam src: SourceFile) extends Tree {
17+
abstract class OpTree(implicit @constructorOnly src: SourceFile) extends Tree {
1818
def op: Ident
1919
override def isTerm: Boolean = op.name.isTermName
2020
override def isType: Boolean = op.name.isTypeName
@@ -23,7 +23,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
2323
/** A typed subtree of an untyped tree needs to be wrapped in a TypedSplice
2424
* @param owner The current owner at the time the tree was defined
2525
*/
26-
abstract case class TypedSplice(splice: tpd.Tree)(val owner: Symbol)(implicit @transientParam src: SourceFile) extends ProxyTree {
26+
abstract case class TypedSplice(splice: tpd.Tree)(val owner: Symbol)(implicit @constructorOnly src: SourceFile) extends ProxyTree {
2727
def forwardTo: tpd.Tree = splice
2828
}
2929

@@ -33,31 +33,31 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
3333
}
3434

3535
/** mods object name impl */
36-
case class ModuleDef(name: TermName, impl: Template)(implicit @transientParam src: SourceFile)
36+
case class ModuleDef(name: TermName, impl: Template)(implicit @constructorOnly src: SourceFile)
3737
extends MemberDef {
3838
type ThisTree[-T >: Untyped] <: Trees.NameTree[T] with Trees.MemberDef[T] with ModuleDef
3939
def withName(name: Name)(implicit ctx: Context): ModuleDef = cpy.ModuleDef(this)(name.toTermName, impl)
4040
}
4141

42-
case class ParsedTry(expr: Tree, handler: Tree, finalizer: Tree)(implicit @transientParam src: SourceFile) extends Tree with TermTree
42+
case class ParsedTry(expr: Tree, handler: Tree, finalizer: Tree)(implicit @constructorOnly src: SourceFile) extends Tree with TermTree
4343

44-
case class SymbolLit(str: String)(implicit @transientParam src: SourceFile) extends TermTree
44+
case class SymbolLit(str: String)(implicit @constructorOnly src: SourceFile) extends TermTree
4545

4646
/** An interpolated string
4747
* @param segments a list of two element tickets consisting of string literal and argument tree,
4848
* possibly with a simple string literal as last element of the list
4949
*/
50-
case class InterpolatedString(id: TermName, segments: List[Tree])(implicit @transientParam src: SourceFile)
50+
case class InterpolatedString(id: TermName, segments: List[Tree])(implicit @constructorOnly src: SourceFile)
5151
extends TermTree
5252

5353
/** A function type */
54-
case class Function(args: List[Tree], body: Tree)(implicit @transientParam src: SourceFile) extends Tree {
54+
case class Function(args: List[Tree], body: Tree)(implicit @constructorOnly src: SourceFile) extends Tree {
5555
override def isTerm: Boolean = body.isTerm
5656
override def isType: Boolean = body.isType
5757
}
5858

5959
/** A function type with `implicit` or `erased` modifiers */
60-
class FunctionWithMods(args: List[Tree], body: Tree, val mods: Modifiers)(implicit @transientParam src: SourceFile)
60+
class FunctionWithMods(args: List[Tree], body: Tree, val mods: Modifiers)(implicit @constructorOnly src: SourceFile)
6161
extends Function(args, body)
6262

6363
/** A function created from a wildcard expression
@@ -67,76 +67,76 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
6767
* This is equivalent to Function, except that forms a special case for the overlapping
6868
* positions tests.
6969
*/
70-
class WildcardFunction(placeholderParams: List[ValDef], body: Tree)(implicit @transientParam src: SourceFile)
70+
class WildcardFunction(placeholderParams: List[ValDef], body: Tree)(implicit @constructorOnly src: SourceFile)
7171
extends Function(placeholderParams, body)
7272

73-
case class InfixOp(left: Tree, op: Ident, right: Tree)(implicit @transientParam src: SourceFile) extends OpTree
74-
case class PostfixOp(od: Tree, op: Ident)(implicit @transientParam src: SourceFile) extends OpTree
75-
case class PrefixOp(op: Ident, od: Tree)(implicit @transientParam src: SourceFile) extends OpTree {
73+
case class InfixOp(left: Tree, op: Ident, right: Tree)(implicit @constructorOnly src: SourceFile) extends OpTree
74+
case class PostfixOp(od: Tree, op: Ident)(implicit @constructorOnly src: SourceFile) extends OpTree
75+
case class PrefixOp(op: Ident, od: Tree)(implicit @constructorOnly src: SourceFile) extends OpTree {
7676
override def isType: Boolean = op.isType
7777
override def isTerm: Boolean = op.isTerm
7878
}
79-
case class Parens(t: Tree)(implicit @transientParam src: SourceFile) extends ProxyTree {
79+
case class Parens(t: Tree)(implicit @constructorOnly src: SourceFile) extends ProxyTree {
8080
def forwardTo: Tree = t
8181
}
82-
case class Tuple(trees: List[Tree])(implicit @transientParam src: SourceFile) extends Tree {
82+
case class Tuple(trees: List[Tree])(implicit @constructorOnly src: SourceFile) extends Tree {
8383
override def isTerm: Boolean = trees.isEmpty || trees.head.isTerm
8484
override def isType: Boolean = !isTerm
8585
}
86-
case class Throw(expr: Tree)(implicit @transientParam src: SourceFile) extends TermTree
87-
case class Quote(expr: Tree)(implicit @transientParam src: SourceFile) extends TermTree
88-
case class DoWhile(body: Tree, cond: Tree)(implicit @transientParam src: SourceFile) extends TermTree
89-
case class ForYield(enums: List[Tree], expr: Tree)(implicit @transientParam src: SourceFile) extends TermTree
90-
case class ForDo(enums: List[Tree], body: Tree)(implicit @transientParam src: SourceFile) extends TermTree
91-
case class GenFrom(pat: Tree, expr: Tree)(implicit @transientParam src: SourceFile) extends Tree
92-
case class GenAlias(pat: Tree, expr: Tree)(implicit @transientParam src: SourceFile) extends Tree
93-
case class ContextBounds(bounds: TypeBoundsTree, cxBounds: List[Tree])(implicit @transientParam src: SourceFile) extends TypTree
94-
case class PatDef(mods: Modifiers, pats: List[Tree], tpt: Tree, rhs: Tree)(implicit @transientParam src: SourceFile) extends DefTree
95-
case class DependentTypeTree(tp: List[Symbol] => Type)(implicit @transientParam src: SourceFile) extends Tree
86+
case class Throw(expr: Tree)(implicit @constructorOnly src: SourceFile) extends TermTree
87+
case class Quote(expr: Tree)(implicit @constructorOnly src: SourceFile) extends TermTree
88+
case class DoWhile(body: Tree, cond: Tree)(implicit @constructorOnly src: SourceFile) extends TermTree
89+
case class ForYield(enums: List[Tree], expr: Tree)(implicit @constructorOnly src: SourceFile) extends TermTree
90+
case class ForDo(enums: List[Tree], body: Tree)(implicit @constructorOnly src: SourceFile) extends TermTree
91+
case class GenFrom(pat: Tree, expr: Tree)(implicit @constructorOnly src: SourceFile) extends Tree
92+
case class GenAlias(pat: Tree, expr: Tree)(implicit @constructorOnly src: SourceFile) extends Tree
93+
case class ContextBounds(bounds: TypeBoundsTree, cxBounds: List[Tree])(implicit @constructorOnly src: SourceFile) extends TypTree
94+
case class PatDef(mods: Modifiers, pats: List[Tree], tpt: Tree, rhs: Tree)(implicit @constructorOnly src: SourceFile) extends DefTree
95+
case class DependentTypeTree(tp: List[Symbol] => Type)(implicit @constructorOnly src: SourceFile) extends Tree
9696

9797
@sharable object EmptyTypeIdent extends Ident(tpnme.EMPTY)(NoSource) with WithoutTypeOrPos[Untyped] {
9898
override def isEmpty: Boolean = true
9999
}
100100

101101
/** A block generated by the XML parser, only treated specially by
102102
* `Positioned#checkPos` */
103-
class XMLBlock(stats: List[Tree], expr: Tree)(implicit @transientParam src: SourceFile) extends Block(stats, expr)
103+
class XMLBlock(stats: List[Tree], expr: Tree)(implicit @constructorOnly src: SourceFile) extends Block(stats, expr)
104104

105105
// ----- Modifiers -----------------------------------------------------
106106
/** Mod is intended to record syntactic information about modifiers, it's
107107
* NOT a replacement of FlagSet.
108108
*
109109
* For any query about semantic information, check `flags` instead.
110110
*/
111-
sealed abstract class Mod(val flags: FlagSet)(implicit @transientParam src: SourceFile)
111+
sealed abstract class Mod(val flags: FlagSet)(implicit @constructorOnly src: SourceFile)
112112
extends Positioned
113113

114114
object Mod {
115-
case class Private()(implicit @transientParam src: SourceFile) extends Mod(Flags.Private)
115+
case class Private()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Private)
116116

117-
case class Protected()(implicit @transientParam src: SourceFile) extends Mod(Flags.Protected)
117+
case class Protected()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Protected)
118118

119-
case class Var()(implicit @transientParam src: SourceFile) extends Mod(Flags.Mutable)
119+
case class Var()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Mutable)
120120

121-
case class Implicit()(implicit @transientParam src: SourceFile) extends Mod(Flags.ImplicitCommon)
121+
case class Implicit()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.ImplicitCommon)
122122

123-
case class Erased()(implicit @transientParam src: SourceFile) extends Mod(Flags.Erased)
123+
case class Erased()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Erased)
124124

125-
case class Final()(implicit @transientParam src: SourceFile) extends Mod(Flags.Final)
125+
case class Final()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Final)
126126

127-
case class Sealed()(implicit @transientParam src: SourceFile) extends Mod(Flags.Sealed)
127+
case class Sealed()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Sealed)
128128

129-
case class Opaque()(implicit @transientParam src: SourceFile) extends Mod(Flags.Opaque)
129+
case class Opaque()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Opaque)
130130

131-
case class Override()(implicit @transientParam src: SourceFile) extends Mod(Flags.Override)
131+
case class Override()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Override)
132132

133-
case class Abstract()(implicit @transientParam src: SourceFile) extends Mod(Flags.Abstract)
133+
case class Abstract()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Abstract)
134134

135-
case class Lazy()(implicit @transientParam src: SourceFile) extends Mod(Flags.Lazy)
135+
case class Lazy()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Lazy)
136136

137-
case class Inline()(implicit @transientParam src: SourceFile) extends Mod(Flags.Inline)
137+
case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline)
138138

139-
case class Enum()(implicit @transientParam src: SourceFile) extends Mod(Flags.Enum)
139+
case class Enum()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Enum)
140140
}
141141

142142
/** Modifiers and annotations for definitions
@@ -215,7 +215,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
215215
/** A type tree that gets its type from some other tree's symbol. Enters the
216216
* type tree in the References attachment of the `from` tree as a side effect.
217217
*/
218-
abstract class DerivedTypeTree(implicit @transientParam src: SourceFile) extends TypeTree {
218+
abstract class DerivedTypeTree(implicit @constructorOnly src: SourceFile) extends TypeTree {
219219

220220
private[this] var myWatched: Tree = EmptyTree
221221

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ class Definitions {
794794
def TASTYLongSignatureAnnot(implicit ctx: Context): ClassSymbol = TASTYLongSignatureAnnotType.symbol.asClass
795795
lazy val TailrecAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.tailrec")
796796
def TailrecAnnot(implicit ctx: Context): ClassSymbol = TailrecAnnotType.symbol.asClass
797-
lazy val TransientParamAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.transientParam")
797+
lazy val TransientParamAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.constructorOnly")
798798
def TransientParamAnnot(implicit ctx: Context): ClassSymbol = TransientParamAnnotType.symbol.asClass
799799
lazy val SwitchAnnotType: TypeRef = ctx.requiredClassRef("scala.annotation.switch")
800800
def SwitchAnnot(implicit ctx: Context): ClassSymbol = SwitchAnnotType.symbol.asClass

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import transform.SymUtils._
1515
import printing.Printer
1616
import printing.Texts._
1717
import util.SourceFile
18-
import annotation.transientParam
18+
import annotation.constructorOnly
1919

2020
object TreePickler {
2121

2222
val sectionName = "ASTs"
2323

24-
case class Hole(idx: Int, args: List[tpd.Tree])(implicit @transientParam src: SourceFile) extends tpd.Tree {
24+
case class Hole(idx: Int, args: List[tpd.Tree])(implicit @constructorOnly src: SourceFile) extends tpd.Tree {
2525
override def fallbackToText(printer: Printer): Text =
2626
s"[[$idx|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
2727
}

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import core.quoted.PickledQuotes
3535
import scala.quoted
3636
import scala.quoted.Types.TreeType
3737
import scala.quoted.Exprs.TastyTreeExpr
38-
import scala.annotation.transientParam
38+
import scala.annotation.constructorOnly
3939
import scala.annotation.internal.sharable
4040

4141
/** Unpickler for typed trees
@@ -106,7 +106,7 @@ class TreeUnpickler(reader: TastyReader,
106106
}
107107
}
108108

109-
class Completer(reader: TastyReader)(implicit @transientParam ctx: Context) extends LazyType {
109+
class Completer(reader: TastyReader)(implicit @constructorOnly ctx: Context) extends LazyType {
110110
import reader._
111111
val owner = ctx.owner
112112
val source = ctx.source

compiler/src/dotty/tools/dotc/tastyreflect/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.Symbols.Symbol
66
import dotty.tools.dotc.core.Types.Type
77
import dotty.tools.dotc.core.SymDenotations.SymDenotation
8-
import scala.annotation.transientParam
8+
import scala.annotation.constructorOnly
99
import util.SourceFile
1010

1111
package object tastyreflect {
1212

1313
type PackageDefinition = PackageDefinitionImpl[Type]
1414

1515
/** Represents the symbol of a definition in tree form */
16-
case class PackageDefinitionImpl[-T >: Untyped] private[tastyreflect] (sym: Symbol)(implicit @transientParam src: SourceFile) extends Tree[T] {
16+
case class PackageDefinitionImpl[-T >: Untyped] private[tastyreflect] (sym: Symbol)(implicit @constructorOnly src: SourceFile) extends Tree[T] {
1717
type ThisTree[-T >: Untyped] = PackageDefinitionImpl[T]
1818

1919
override def denot(implicit ctx: Context): SymDenotation = sym.denot

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import reporting.trace
3030
import Constants.{Constant, IntTag, LongTag}
3131
import dotty.tools.dotc.reporting.diagnostic.messages.{NotAnExtractor, UnapplyInvalidNumberOfArguments}
3232
import Denotations.SingleDenotation
33-
import annotation.transientParam
33+
import annotation.constructorOnly
3434

3535
object Applications {
3636
import tpd._
@@ -169,7 +169,7 @@ object Applications {
169169

170170
/** A wrapper indicating that its argument is an application of an extension method.
171171
*/
172-
class ExtMethodApply(val app: Tree)(implicit @transientParam src: SourceFile) extends tpd.Tree {
172+
class ExtMethodApply(val app: Tree)(implicit @constructorOnly src: SourceFile) extends tpd.Tree {
173173
override def span = app.span
174174

175175
def canEqual(that: Any): Boolean = app.canEqual(that)

library/src/scala/annotation/transientParam.scala renamed to library/src/scala/annotation/constructorOnly.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import scala.annotation.meta._
1313
/** An annotation that goes on parameters of classes or traits. It asserts
1414
* that the parameter is used only for initialization and is not kept in
1515
* the class as a field. Violations of this assertion are flagged as
16-
* compile errors. The annotatoon is particularly useful for implicit
16+
* compile errors. The annotation is particularly useful for implicit
1717
* parameters since for these a textual scan is not sufficient to know
1818
* where they are used.
1919
*/
20-
@param class transientParam extends scala.annotation.StaticAnnotation
20+
@param class constructorOnly extends scala.annotation.StaticAnnotation

tests/neg/constructor-only.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import annotation.constructorOnly
2+
class Context
3+
4+
class Test1()(implicit @constructorOnly ctx: Context) { // error
5+
def test1 = implicitly[Context]
6+
}
7+
8+
class Test2()(@constructorOnly ctx: Context) { // error
9+
def test1 = ctx
10+
}
11+
12+
class Test3()(implicit @constructorOnly ctx: Context) { // OK
13+
val foo = implicitly[Context]
14+
}

tests/neg/transient-param.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)