@@ -14,7 +14,7 @@ import typer.RefChecks.{checkAllOverrides, checkSelfAgainstParents, OverridingPa
14
14
import typer .Checking .{checkBounds , checkAppliedTypesIn }
15
15
import typer .ErrorReporting .{Addenda , err }
16
16
import typer .ProtoTypes .{AnySelectionProto , LhsProto }
17
- import util .{SimpleIdentitySet , EqHashMap , SrcPos , Property }
17
+ import util .{SimpleIdentitySet , EqHashMap , EqHashSet , SrcPos , Property }
18
18
import transform .SymUtils .*
19
19
import transform .{Recheck , PreRecheck }
20
20
import Recheck .*
@@ -147,6 +147,8 @@ object CheckCaptures:
147
147
private def disallowRootCapabilitiesIn (tp : Type , carrier : Symbol , what : String , have : String , addendum : String , pos : SrcPos )(using Context ) =
148
148
val check = new TypeTraverser :
149
149
150
+ private val seen = new EqHashSet [TypeRef ]
151
+
150
152
extension (tparam : Symbol ) def isParametricIn (carrier : Symbol ): Boolean =
151
153
val encl = carrier.maybeOwner.enclosingMethodOrClass
152
154
if encl.isClass then tparam.isParametricIn(encl)
@@ -160,19 +162,21 @@ object CheckCaptures:
160
162
def traverse (t : Type ) =
161
163
t.dealiasKeepAnnots match
162
164
case t : TypeRef =>
163
- capt.println(i " disallow $t, $tp, $what, ${t.isSealed}" )
164
- t.info match
165
- case TypeBounds (_, hi) if ! t.isSealed && ! t.symbol.isParametricIn(carrier) =>
166
- if hi.isAny then
167
- report.error(
168
- em """ $what cannot $have $tp since
169
- |that type refers to the type variable $t, which is not sealed.
170
- | $addendum""" ,
171
- pos)
172
- else
173
- traverse(hi)
174
- case _ =>
175
- traverseChildren(t)
165
+ if ! seen.contains(t) then
166
+ capt.println(i " disallow $t, $tp, $what, ${t.isSealed}" )
167
+ seen += t
168
+ t.info match
169
+ case TypeBounds (_, hi) if ! t.isSealed && ! t.symbol.isParametricIn(carrier) =>
170
+ if hi.isAny then
171
+ report.error(
172
+ em """ $what cannot $have $tp since
173
+ |that type refers to the type variable $t, which is not sealed.
174
+ | $addendum""" ,
175
+ pos)
176
+ else
177
+ traverse(hi)
178
+ case _ =>
179
+ traverseChildren(t)
176
180
case AnnotatedType (_, ann) if ann.symbol == defn.UncheckedCapturesAnnot =>
177
181
()
178
182
case t =>
0 commit comments