Skip to content

Commit 584b858

Browse files
committed
Better interop for non-capture-checked file for bounds checking
Supress bounds checking in CheckCaptures if the type constructor of an applied type has not been compiled with capture checking.
1 parent f914ff8 commit 584b858

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,17 @@ object Checking {
146146
def traverse(tp: Type) =
147147
tp match
148148
case AppliedType(tycon, argTypes)
149-
if !(tycon.typeSymbol.is(JavaDefined) && ctx.compilationUnit.isJava) =>
149+
if !(tycon.typeSymbol.is(JavaDefined) && ctx.compilationUnit.isJava)
150150
// Don't check bounds in Java units that refer to Java type constructors.
151151
// Scala is not obliged to do Java type checking and in fact i17763 goes wrong
152152
// if we attempt to check bounds of F-bounded mutually recursive Java interfaces.
153153
// Do check all bounds in Scala units and those bounds in Java units that
154154
// occur in applications of Scala type constructors.
155+
&& !(ctx.phase == Phases.checkCapturesPhase && !tycon.typeSymbol.is(CaptureChecked))
156+
// Don't check bounds when capture checking type constructors that were not
157+
// themselves capture checked. Since the type constructor could not foresee
158+
// possible capture sets, it's better to be lenient for backwards compatibility.
159+
=>
155160
checkAppliedType(
156161
untpd.AppliedTypeTree(TypeTree(tycon), argTypes.map(TypeTree(_)))
157162
.withType(tp).withSpan(tpt.span.toSynthetic),

0 commit comments

Comments
 (0)