@@ -107,7 +107,7 @@ object Summarization {
107107
108108 case Typed (expr, tpt) =>
109109 if (tpt.tpe.hasAnnotation(defn.UncheckedAnnot )) Summary .empty
110- else analyze(expr)
110+ else analyze(expr) ++ effectsOfType(tpt.tpe, tpt)
111111
112112 case NamedArg (name, arg) =>
113113 analyze(arg)
@@ -140,7 +140,7 @@ object Summarization {
140140 val Summary (pots, effs) = analyze(selector)
141141 val init = Summary (Potentials .empty, pots.promote(selector) ++ effs)
142142 cases.foldLeft(init) { (acc, cas) =>
143- acc union analyze(cas.body)
143+ acc + analyze(cas.body)
144144 }
145145
146146 // case CaseDef(pat, guard, body) =>
@@ -162,7 +162,7 @@ object Summarization {
162162
163163 case Try (block, cases, finalizer) =>
164164 val Summary (pots, effs) = cases.foldLeft(analyze(block)) { (acc, cas) =>
165- acc union analyze(cas.body)
165+ acc + analyze(cas.body)
166166 }
167167 val Summary (_, eff2) = if (finalizer.isEmpty) Summary .empty else analyze(finalizer)
168168 Summary (pots, effs ++ eff2)
@@ -199,8 +199,9 @@ object Summarization {
199199 Summary (pots.promote(ddef) ++ effs)
200200 }
201201
202- case _ : TypeDef =>
203- Summary .empty
202+ case tdef : TypeDef =>
203+ if tdef.isClassDef then Summary .empty
204+ else Summary (effectsOfType(tdef.symbol.info, tdef.rhs))
204205
205206 case _ : Import | _ : Export =>
206207 Summary .empty
@@ -213,6 +214,19 @@ object Summarization {
213214 else summary
214215 }
215216
217+ private def effectsOfType (tp : Type , source : Tree )(implicit env : Env ): Effects =
218+ var summary = Summary .empty
219+ val traverser = new TypeTraverser {
220+ def traverse (tp : Type ): Unit = tp match {
221+ case TermRef (_ : SingletonType , _) =>
222+ summary = summary + analyze(tp, source)
223+ case _ =>
224+ traverseChildren(tp)
225+ }
226+ }
227+ traverser.traverse(tp)
228+ summary.effs
229+
216230 def analyze (tp : Type , source : Tree )(implicit env : Env ): Summary =
217231 trace(" summarizing " + tp.show, init, s => s.asInstanceOf [Summary ].show) {
218232 val summary : Summary = tp match {
@@ -243,8 +257,12 @@ object Summarization {
243257 }
244258 Summary (pots2, effs)
245259
260+ case _ : TermParamRef | _ : RecThis =>
261+ // possible from checking effects of types
262+ Summary .empty
263+
246264 case _ =>
247- throw new Exception (" unexpected type: " + tp.show )
265+ throw new Exception (" unexpected type: " + tp)
248266 }
249267
250268 if (env.isAlwaysInitialized(tp)) Summary (Potentials .empty, summary.effs)
@@ -290,7 +308,7 @@ object Summarization {
290308 def parentArgEffsWithInit (stats : List [Tree ], ctor : Symbol , source : Tree ): Effects =
291309 val init =
292310 if env.canIgnoreMethod(ctor) then Effects .empty
293- else Effects .empty + MethodCall (ThisRef ()(source), ctor)(source)
311+ else Effects .empty : + MethodCall (ThisRef ()(source), ctor)(source)
294312 stats.foldLeft(init) { (acc, stat) =>
295313 val summary = Summarization .analyze(stat)
296314 acc ++ summary.effs
@@ -320,7 +338,7 @@ object Summarization {
320338 if tref.prefix == NoPrefix then Effects .empty
321339 else Summarization .analyze(tref.prefix, ref).effs
322340
323- prefixEff + MethodCall (ThisRef ()(ref), ctor)(ref)
341+ prefixEff :+ MethodCall (ThisRef ()(ref), ctor)(ref)
324342 }
325343 })
326344 }
0 commit comments