@@ -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
@@ -2285,11 +2286,29 @@ object Parsers {
2285
2286
2286
2287
/** TypeBounds ::= [`>:' TypeBound ] [`<:' TypeBound ]
2287
2288
* TypeBound ::= Type
2288
- * | CaptureSet -- under captureChecking
2289
+ * | CaptureSet -- under captureChecking
2289
2290
*/
2290
2291
def typeBounds (isCapParamOrMem : Boolean = false ): TypeBoundsTree =
2292
+ def isCapsBound (t : Tree ): Boolean =
2293
+ t match
2294
+ case Select (qual, tpnme.CapSet ) => true
2295
+ case Annotated (Select (qual, tpnme.CapSet ), _) => true
2296
+ case _ => false
2297
+
2291
2298
atSpan(in.offset):
2292
- TypeBoundsTree (bound(SUPERTYPE , isCapParamOrMem), bound(SUBTYPE , isCapParamOrMem))
2299
+ var lbound = bound(SUPERTYPE , isCapParamOrMem)
2300
+ var ubound = bound(SUBTYPE , isCapParamOrMem)
2301
+ if Feature .ccEnabled && ! isCapParamOrMem then
2302
+ /* We haven't annotated the `^` to a type parameter/member,
2303
+ but an explicit capture-set bound makes it a capture parameter, so we make sure
2304
+ to add the missing other CapSet bound. */
2305
+ if lbound.isEmpty && isCapsBound(ubound) then
2306
+ lbound = capsBound(Nil , isLowerBound = true )
2307
+ if ubound.isEmpty && isCapsBound(lbound) then
2308
+ ubound = capsBound(Nil , isLowerBound = false )
2309
+ end if
2310
+ TypeBoundsTree (lbound, ubound)
2311
+ end typeBounds
2293
2312
2294
2313
private def bound (tok : Int , isCapParamOrMem : Boolean = false ): Tree =
2295
2314
if (in.token == tok) then
@@ -2298,7 +2317,8 @@ object Parsers {
2298
2317
capsBound(captureSet(), isLowerBound = tok == SUPERTYPE )
2299
2318
else toplevelTyp()
2300
2319
else if Feature .ccEnabled && isCapParamOrMem then
2301
- capsBound(Nil , isLowerBound = tok == SUPERTYPE ) // FIXME: should we avoid the CapSet^{} lower bound and make it Nothing?
2320
+ // we hit this case if we have annotated a post-fix `^` but no bounds to a type parameter/member
2321
+ capsBound(Nil , isLowerBound = tok == SUPERTYPE )
2302
2322
else EmptyTree
2303
2323
2304
2324
private def capsBound (refs : List [Tree ], isLowerBound : Boolean = false ): Tree =
0 commit comments