@@ -41,6 +41,8 @@ object Checking {
41
41
visited += eff
42
42
copy(path = this .path :+ eff.source)
43
43
}
44
+
45
+ def withOwner (sym : Symbol ): State = copy(env = env.withOwner(sym))
44
46
}
45
47
46
48
private implicit def theEnv (implicit state : State ): Env = state.env
@@ -58,10 +60,10 @@ object Checking {
58
60
// mark current class as initialized, required for linearization
59
61
state.parentsInited += cls
60
62
61
- def checkClassBodyStat (tree : Tree )(using Context ): Unit = traceOp(" checking " + tree.show, init) {
63
+ def checkClassBodyStat (tree : Tree )(implicit state : State ): Unit = traceOp(" checking " + tree.show, init) {
62
64
tree match {
63
65
case vdef : ValDef =>
64
- val (pots, effs) = Summarization .analyze(vdef.rhs)(theEnv.withOwner(vdef.symbol))
66
+ val (pots, effs) = Summarization .analyze(vdef.rhs)
65
67
theEnv.summaryOf(cls).cacheFor(vdef.symbol, (pots, effs))
66
68
if (! vdef.symbol.is(Flags .Lazy )) {
67
69
checkEffectsIn(effs, cls)
@@ -79,17 +81,35 @@ object Checking {
79
81
// see spec 5.1 about "Template Evaluation".
80
82
// https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html
81
83
82
- def checkCtor (ctor : Symbol , tp : Type , source : Tree )(using Context ): Unit = {
84
+ def checkCtor (ctor : Symbol , tp : Type , source : Tree )(implicit state : State ): Unit = traceOp( " checking " + ctor.show, init) {
83
85
val cls = ctor.owner
84
86
val classDef = cls.defTree
85
87
if (! classDef.isEmpty) {
86
- if (ctor.isPrimaryConstructor) checkClassBody(classDef.asInstanceOf [TypeDef ])
87
- else checkSecondaryConstructor(ctor)
88
+ if (ctor.isPrimaryConstructor) checkClassBody(classDef.asInstanceOf [TypeDef ])(state.withOwner(cls))
89
+ else checkSecondaryConstructor(ctor)(state.withOwner(cls))
88
90
}
89
91
else if (! cls.isOneOf(Flags .EffectivelyOpenFlags ))
90
92
report.warning(" Inheriting non-open class may cause initialization errors" , source.srcPos)
91
93
}
92
94
95
+ def checkSecondaryConstructor (ctor : Symbol )(implicit state : State ): Unit = traceOp(" checking " + ctor.show, init) {
96
+ val Block (ctorCall :: stats, expr) = ctor.defTree.asInstanceOf [DefDef ].rhs
97
+ val cls = ctor.owner.asClass
98
+
99
+ traceOp(" check ctor: " + ctorCall.show, init) {
100
+ val ctor = ctorCall.symbol
101
+ if (ctor.isPrimaryConstructor)
102
+ checkClassBody(cls.defTree.asInstanceOf [TypeDef ])
103
+ else
104
+ checkSecondaryConstructor(ctor)
105
+ }
106
+
107
+ (stats :+ expr).foreach { stat =>
108
+ val (_, effs) = Summarization .analyze(stat)(theEnv.withOwner(ctor))
109
+ checkEffectsIn(effs, cls)
110
+ }
111
+ }
112
+
93
113
cls.paramAccessors.foreach { acc =>
94
114
if (! acc.is(Flags .Method )) {
95
115
traceIndented(acc.show + " initialized" , init)
@@ -120,24 +140,6 @@ object Checking {
120
140
tpl.body.foreach { checkClassBodyStat(_) }
121
141
}
122
142
123
- def checkSecondaryConstructor (ctor : Symbol )(implicit state : State ): Unit = traceOp(" checking " + ctor.show, init) {
124
- val Block (ctorCall :: stats, expr) = ctor.defTree.asInstanceOf [DefDef ].rhs
125
- val cls = ctor.owner.asClass
126
-
127
- traceOp(" check ctor: " + ctorCall.show, init) {
128
- val ctor = ctorCall.symbol
129
- if (ctor.isPrimaryConstructor)
130
- checkClassBody(cls.defTree.asInstanceOf [TypeDef ])
131
- else
132
- checkSecondaryConstructor(ctor)
133
- }
134
-
135
- (stats :+ expr).foreach { stat =>
136
- val (_, effs) = Summarization .analyze(stat)(theEnv.withOwner(ctor))
137
- checkEffectsIn(effs, cls)
138
- }
139
- }
140
-
141
143
private def checkEffectsIn (effs : Effects , cls : ClassSymbol )(implicit state : State ): Unit = traceOp(" checking effects " + Effects .show(effs), init) {
142
144
for {
143
145
eff <- effs
0 commit comments