@@ -35,6 +35,7 @@ import config.SourceVersion.*
35
35
import config .SourceVersion
36
36
import dotty .tools .dotc .config .MigrationVersion
37
37
import dotty .tools .dotc .util .chaining .*
38
+ import dotty .tools .dotc .config .Printers .variances
38
39
39
40
object Parsers {
40
41
@@ -2275,11 +2276,29 @@ object Parsers {
2275
2276
2276
2277
/** TypeBounds ::= [`>:' TypeBound ] [`<:' TypeBound ]
2277
2278
* TypeBound ::= Type
2278
- * | CaptureSet -- under captureChecking
2279
+ * | CaptureSet -- under captureChecking
2279
2280
*/
2280
2281
def typeBounds (isCapParamOrMem : Boolean = false ): TypeBoundsTree =
2282
+ def isCapsBound (t : Tree ): Boolean =
2283
+ t match
2284
+ case Select (qual, tpnme.CapSet ) => true
2285
+ case Annotated (Select (qual, tpnme.CapSet ), _) => true
2286
+ case _ => false
2287
+
2281
2288
atSpan(in.offset):
2282
- TypeBoundsTree (bound(SUPERTYPE , isCapParamOrMem), bound(SUBTYPE , isCapParamOrMem))
2289
+ var lbound = bound(SUPERTYPE , isCapParamOrMem)
2290
+ var ubound = bound(SUBTYPE , isCapParamOrMem)
2291
+ if Feature .ccEnabled && ! isCapParamOrMem then
2292
+ /* We haven't annotated the `^` to a type parameter/member,
2293
+ but an explicit capture-set bound makes it a capture parameter, so we make sure
2294
+ to add the missing other CapSet bound. */
2295
+ if lbound.isEmpty && isCapsBound(ubound) then
2296
+ lbound = capsBound(Nil , isLowerBound = true )
2297
+ if ubound.isEmpty && isCapsBound(lbound) then
2298
+ ubound = capsBound(Nil , isLowerBound = false )
2299
+ end if
2300
+ TypeBoundsTree (lbound, ubound)
2301
+ end typeBounds
2283
2302
2284
2303
private def bound (tok : Int , isCapParamOrMem : Boolean = false ): Tree =
2285
2304
if (in.token == tok) then
@@ -2288,7 +2307,8 @@ object Parsers {
2288
2307
capsBound(captureSet(), isLowerBound = tok == SUPERTYPE )
2289
2308
else toplevelTyp()
2290
2309
else if Feature .ccEnabled && isCapParamOrMem then
2291
- capsBound(Nil , isLowerBound = tok == SUPERTYPE ) // FIXME: should we avoid the CapSet^{} lower bound and make it Nothing?
2310
+ // we hit this case if we have annotated a post-fix `^` but no bounds to a type parameter/member
2311
+ capsBound(Nil , isLowerBound = tok == SUPERTYPE )
2292
2312
else EmptyTree
2293
2313
2294
2314
private def capsBound (refs : List [Tree ], isLowerBound : Boolean = false ): Tree =
0 commit comments