Skip to content

Commit 65c0a8c

Browse files
Backport "Remove linearization requirement for override ref checks from java classes" to LTS (#20765)
Backports #18953 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 6eebcaf + 37dc190 commit 65c0a8c

13 files changed

+82
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,23 @@ object RefChecks {
219219
false
220220
precedesIn(parent.asClass.baseClasses)
221221

222-
// We can exclude pairs safely from checking only under three additional conditions
223-
// - their signatures also match in the parent class.
224-
// See neg/i12828.scala for an example where this matters.
225-
// - They overriding/overridden appear in linearization order.
226-
// See neg/i5094.scala for an example where this matters.
227-
// - The overridden symbol is not `abstract override`. For such symbols
228-
// we need a more extensive test since the virtual super chain depends
229-
// on the precise linearization order, which might be different for the
230-
// subclass. See neg/i14415.scala.
222+
/** We can exclude pairs safely from checking only under three additional conditions
223+
* - their signatures also match in the parent class.
224+
* See neg/i12828.scala for an example where this matters.
225+
* - They overriding/overridden appear in linearization order.
226+
* See neg/i5094.scala for an example where this matters.
227+
* - They overriding/overridden appear in linearization order,
228+
* or the parent is a Java class (because linearization does not apply to java classes).
229+
* See neg/i5094.scala and pos/i18654.scala for examples where this matters.
230+
* - The overridden symbol is not `abstract override`. For such symbols
231+
* we need a more extensive test since the virtual super chain depends
232+
* on the precise linearization order, which might be different for the
233+
* subclass. See neg/i14415.scala.
234+
*/
231235
override def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parent: Symbol): Boolean =
232236
isOverridingPair(sym1, sym2, parent.thisType)
233237
.showing(i"already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parent.thisType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parent.thisType).signature} = $result", refcheck)
234-
&& inLinearizationOrder(sym1, sym2, parent)
238+
&& (inLinearizationOrder(sym1, sym2, parent) || parent.is(JavaDefined))
235239
&& !sym2.is(AbsOverride)
236240

237241
// Checks the subtype relationship tp1 <:< tp2.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
import org.jooq.impl.TableRecordImpl
3+
4+
class TRecord extends TableRecordImpl[TRecord](null) {}

sbt-test/java-compat/i18764/build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
scalaVersion := sys.props("plugin.scalaVersion")
3+
4+
lazy val dependencies = Seq(
5+
"org.jooq" % "jooq-codegen" % "3.18.7",
6+
)
7+
8+
lazy val jooqtest = (project in file("."))
9+
.settings(libraryDependencies ++= dependencies)

sbt-test/java-compat/i18764/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> compile
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jooq.impl;
2+
3+
import org.jooq.Configuration;
4+
5+
abstract class AbstractQueryPart {
6+
Configuration configuration() {
7+
return null;
8+
}
9+
}

tests/pos/i18654/AbstractRoutine.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.jooq.impl;
2+
3+
import org.jooq.Configuration;
4+
import org.jooq.Attachable;
5+
6+
public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Attachable {
7+
@Override
8+
public final Configuration configuration() {
9+
return null;
10+
}
11+
}

tests/pos/i18654/Attachable.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.jooq;
2+
3+
public interface Attachable {
4+
Configuration configuration();
5+
}

tests/pos/i18654/Configuration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package org.jooq;
2+
3+
public interface Configuration {}

tests/pos/i18654/MyRoutineScala.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.example
2+
3+
import org.jooq.impl.AbstractRoutine
4+
5+
// Works in Scala 2.12 and 2.13 but is broken in Scala 3
6+
class MyRoutineScala extends AbstractRoutine[String] {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
class MyRunConfigurationScala extends RunConfigurationBase
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
public interface RunConfiguration extends Cloneable {
3+
RunConfiguration clone();
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public abstract class RunConfigurationBase<T> extends UserDataHolderBase implements RunConfiguration {
2+
@Override
3+
public RunConfiguration clone() {
4+
return null;
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.util.concurrent.atomic.AtomicReference;
2+
3+
public class UserDataHolderBase extends AtomicReference<String> {
4+
@Override
5+
protected Object clone() {
6+
return null;
7+
}
8+
}

0 commit comments

Comments
 (0)