Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Remove linearization requirement for override ref checks from java classes" to LTS #20765

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,23 @@ object RefChecks {
false
precedesIn(parent.asClass.baseClasses)

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

// Checks the subtype relationship tp1 <:< tp2.
Expand Down
4 changes: 4 additions & 0 deletions sbt-test/java-compat/i18764/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import org.jooq.impl.TableRecordImpl

class TRecord extends TableRecordImpl[TRecord](null) {}
9 changes: 9 additions & 0 deletions sbt-test/java-compat/i18764/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

scalaVersion := sys.props("plugin.scalaVersion")

lazy val dependencies = Seq(
"org.jooq" % "jooq-codegen" % "3.18.7",
)

lazy val jooqtest = (project in file("."))
.settings(libraryDependencies ++= dependencies)
1 change: 1 addition & 0 deletions sbt-test/java-compat/i18764/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile
9 changes: 9 additions & 0 deletions tests/pos/i18654/AbstractQueryPart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jooq.impl;

import org.jooq.Configuration;

abstract class AbstractQueryPart {
Configuration configuration() {
return null;
}
}
11 changes: 11 additions & 0 deletions tests/pos/i18654/AbstractRoutine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jooq.impl;

import org.jooq.Configuration;
import org.jooq.Attachable;

public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Attachable {
@Override
public final Configuration configuration() {
return null;
}
}
5 changes: 5 additions & 0 deletions tests/pos/i18654/Attachable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.jooq;

public interface Attachable {
Configuration configuration();
}
3 changes: 3 additions & 0 deletions tests/pos/i18654/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.jooq;

public interface Configuration {}
6 changes: 6 additions & 0 deletions tests/pos/i18654/MyRoutineScala.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example

import org.jooq.impl.AbstractRoutine

// Works in Scala 2.12 and 2.13 but is broken in Scala 3
class MyRoutineScala extends AbstractRoutine[String] {}
2 changes: 2 additions & 0 deletions tests/pos/i19007/MyRunConfigurationScala.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

class MyRunConfigurationScala extends RunConfigurationBase
4 changes: 4 additions & 0 deletions tests/pos/i19007/RunConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

public interface RunConfiguration extends Cloneable {
RunConfiguration clone();
}
6 changes: 6 additions & 0 deletions tests/pos/i19007/RunConfigurationBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public abstract class RunConfigurationBase<T> extends UserDataHolderBase implements RunConfiguration {
@Override
public RunConfiguration clone() {
return null;
}
}
8 changes: 8 additions & 0 deletions tests/pos/i19007/UserDataHolderBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.util.concurrent.atomic.AtomicReference;

public class UserDataHolderBase extends AtomicReference<String> {
@Override
protected Object clone() {
return null;
}
}