Skip to content

Commit c528979

Browse files
authored
Don't check bounds of Java applications in Java units (#18054)
Something goes wrong when we try to do mutually recursive F-bounds checking in Java units. I am not sure what exactly. But in any case, Scala should not try to do Java's typechecking. So we now check applications in Java units only if they refer to Scala classes. I added a test for #7494, which was originally addressed by #9370, the PR which introduced the Java bounds checking. Adding the test ensures that the new restrictions still flag the original error. Fixes #17763
2 parents 46b30cc + f3d63f0 commit c528979

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ object Checking {
145145
val checker = new TypeTraverser:
146146
def traverse(tp: Type) =
147147
tp match
148-
case AppliedType(tycon, argTypes) =>
148+
case AppliedType(tycon, argTypes)
149+
if !(tycon.typeSymbol.is(JavaDefined) && ctx.compilationUnit.isJava) =>
150+
// Don't check bounds in Java units that refer to Java type constructors.
151+
// Scala is not obliged to do Java type checking and in fact i17763 goes wrong
152+
// if we attempt to check bounds of F-bounded mutually recursive Java interfaces.
153+
// Do check all bounds in Scala units and those bounds in Java units that
154+
// occur in applications of Scala type constructors.
149155
checkAppliedType(
150156
untpd.AppliedTypeTree(TypeTree(tycon), argTypes.map(TypeTree(_)))
151157
.withType(tp).withSpan(tpt.span.toSynthetic),

tests/pos/i17763/CopyableBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public interface CopyableBuilder<B extends CopyableBuilder<B, T>, T extends ToCopyableBuilder<B, T>> {
2+
}

tests/pos/i17763/Crash.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Crash
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public interface ToCopyableBuilder<B extends CopyableBuilder<B, T>, T extends ToCopyableBuilder<B, T>> {
2+
}

0 commit comments

Comments
 (0)