From 24215819d4ab1e708936118b56c46bbafaba83be Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 11 Mar 2024 15:29:16 +0100 Subject: [PATCH 1/3] Revert "Followup fix to transparent inline conversion (#18130)" This reverts commit 3de184c8dde00948641b8eee8a9988afb3328ab4. --- .../dotty/tools/dotc/typer/ProtoTypes.scala | 20 +++----------- tests/neg/i9685bis.check | 9 ------- tests/neg/i9685bis.scala | 25 ----------------- tests/pos-macros/i18123.scala | 27 ------------------- 4 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 tests/neg/i9685bis.check delete mode 100644 tests/neg/i9685bis.scala delete mode 100644 tests/pos-macros/i18123.scala diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index c8012bef0904..96b0be6d9bd8 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -18,7 +18,6 @@ import ErrorReporting.* import util.SourceFile import TypeComparer.necessarySubType import dotty.tools.dotc.core.Flags.Transparent -import dotty.tools.dotc.config.{ Feature, SourceVersion } import scala.annotation.internal.sharable import dotty.tools.dotc.util.Spans.{NoSpan, Span} @@ -115,22 +114,9 @@ object ProtoTypes { * achieved by replacing expected type parameters with wildcards. */ def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean = - if (Inlines.isInlineable(meth)) { - // Stricter behaviour in 3.4+: do not apply `wildApprox` to non-transparent inlines - if (Feature.sourceVersion.isAtLeast(SourceVersion.`3.4`)) { - if (meth.is(Transparent)) { - constrainResult(mt, wildApprox(pt)) - // do not constrain the result type of transparent inline methods - true - } else { - constrainResult(mt, pt) - } - } else { - // Best-effort to fix https://github.com/scala/scala3/issues/9685 in the 3.3.x series - // while preserving source compatibility as much as possible - val methodMatchedType = constrainResult(mt, wildApprox(pt)) - meth.is(Transparent) || methodMatchedType - } + if (Inlines.isInlineable(meth) && meth.is(Transparent)) { + constrainResult(mt, wildApprox(pt)) + true } else constrainResult(mt, pt) } diff --git a/tests/neg/i9685bis.check b/tests/neg/i9685bis.check deleted file mode 100644 index 1cc81df9987c..000000000000 --- a/tests/neg/i9685bis.check +++ /dev/null @@ -1,9 +0,0 @@ --- [E008] Not Found Error: tests/neg/i9685bis.scala:25:4 --------------------------------------------------------------- -25 | 1.asdf // error - | ^^^^^^ - | value asdf is not a member of Int, but could be made available as an extension method. - | - | The following import might make progress towards fixing the problem: - | - | import foo.Baz.toBaz - | diff --git a/tests/neg/i9685bis.scala b/tests/neg/i9685bis.scala deleted file mode 100644 index 0a3e245fe738..000000000000 --- a/tests/neg/i9685bis.scala +++ /dev/null @@ -1,25 +0,0 @@ -//> using options -source future - -package foo - -import scala.language.implicitConversions - -class Foo - -object Foo: - - inline implicit def toFoo(x: Int): Foo = Foo() - -class Bar - -object Bar: - inline given Conversion[Int, Bar] with - def apply(x: Int): Bar = Bar() - -class Baz - -object Baz: - transparent inline implicit def toBaz(x: Int): Baz = Baz() - -object Usage: - 1.asdf // error diff --git a/tests/pos-macros/i18123.scala b/tests/pos-macros/i18123.scala deleted file mode 100644 index d9127a918ee8..000000000000 --- a/tests/pos-macros/i18123.scala +++ /dev/null @@ -1,27 +0,0 @@ -// may not compile anymore in Scala 3.4+ -package pkg - -import scala.language.`3.3` - -trait P[+T] - -extension [T](inline parse0: P[T]) - inline def | [V >: T](inline other: P[V]): P[V] = ??? - -extension [T](inline parse0: => P[T]) - inline def rep[V](inline min: Int = 0)(using repeater: Implicits.Repeater[T, V]): P[V] = ??? - -object Implicits: - trait Repeater[-T, R] - object Repeater: - implicit def GenericRepeaterImplicit[T]: Repeater[T, Seq[T]] = ??? - -sealed trait RegexTree -abstract class Node extends RegexTree -class CharClassIntersection() extends Node - -def classItem: P[RegexTree] = ??? -def charClassIntersection: P[CharClassIntersection] = ??? - -def x = - (charClassIntersection.rep() | classItem.rep()) From b28d4c1cbe0a552091be7c83ea82924db636d7b2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 11 Mar 2024 15:37:08 +0100 Subject: [PATCH 2/3] Revert "Take into account the result type of inline implicit conversions unless they are transparent" This reverts commit eb38e1f0fc38313ab17969a74664618900ace2e9. --- community-build/community-projects/munit | 2 +- community-build/community-projects/specs2 | 2 +- .../dotty/tools/dotc/typer/ProtoTypes.scala | 5 ++-- tests/neg-macros/i18174.scala | 27 ------------------- tests/neg-macros/i9685bis.check | 9 ------- tests/neg-macros/i9685bis.scala | 23 ---------------- 6 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 tests/neg-macros/i18174.scala delete mode 100644 tests/neg-macros/i9685bis.check delete mode 100644 tests/neg-macros/i9685bis.scala diff --git a/community-build/community-projects/munit b/community-build/community-projects/munit index c18fddb143b9..5c77d7316fc6 160000 --- a/community-build/community-projects/munit +++ b/community-build/community-projects/munit @@ -1 +1 @@ -Subproject commit c18fddb143b98e4c026dc118687410d52b187d88 +Subproject commit 5c77d7316fc66adaed64e9532ee0a45a668b01ec diff --git a/community-build/community-projects/specs2 b/community-build/community-projects/specs2 index ba01cca013d9..a618330aa808 160000 --- a/community-build/community-projects/specs2 +++ b/community-build/community-projects/specs2 @@ -1 +1 @@ -Subproject commit ba01cca013d9d99e390d17619664bdedd716e0d7 +Subproject commit a618330aa80833787859dae805d02e45d4304c42 diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 96b0be6d9bd8..46c12b244fbb 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -17,7 +17,6 @@ import Inferencing.* import ErrorReporting.* import util.SourceFile import TypeComparer.necessarySubType -import dotty.tools.dotc.core.Flags.Transparent import scala.annotation.internal.sharable import dotty.tools.dotc.util.Spans.{NoSpan, Span} @@ -107,14 +106,14 @@ object ProtoTypes { if !res then ctx.typerState.constraint = savedConstraint res - /** Constrain result with special case if `meth` is a transparent inlineable method in an inlineable context. + /** Constrain result with special case if `meth` is an inlineable method in an inlineable context. * In that case, we should always succeed and not constrain type parameters in the expected type, * because the actual return type can be a subtype of the currently known return type. * However, we should constrain parameters of the declared return type. This distinction is * achieved by replacing expected type parameters with wildcards. */ def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean = - if (Inlines.isInlineable(meth) && meth.is(Transparent)) { + if (Inlines.isInlineable(meth)) { constrainResult(mt, wildApprox(pt)) true } diff --git a/tests/neg-macros/i18174.scala b/tests/neg-macros/i18174.scala deleted file mode 100644 index 8bb5ffd51a3f..000000000000 --- a/tests/neg-macros/i18174.scala +++ /dev/null @@ -1,27 +0,0 @@ -// does not compile anymore in Scala 3.4+ -package pkg - -import scala.language.`3.4` - -trait P[+T] - -extension [T](inline parse0: P[T]) - inline def | [V >: T](inline other: P[V]): P[V] = ??? - -extension [T](inline parse0: => P[T]) - inline def rep[V](inline min: Int = 0)(using repeater: Implicits.Repeater[T, V]): P[V] = ??? - -object Implicits: - trait Repeater[-T, R] - object Repeater: - implicit def GenericRepeaterImplicit[T]: Repeater[T, Seq[T]] = ??? - -sealed trait RegexTree -abstract class Node extends RegexTree -class CharClassIntersection() extends Node - -def classItem: P[RegexTree] = ??? -def charClassIntersection: P[CharClassIntersection] = ??? - -def x = - (charClassIntersection.rep() | classItem.rep()) // error diff --git a/tests/neg-macros/i9685bis.check b/tests/neg-macros/i9685bis.check deleted file mode 100644 index 45e7f85aa30d..000000000000 --- a/tests/neg-macros/i9685bis.check +++ /dev/null @@ -1,9 +0,0 @@ --- [E008] Not Found Error: tests/neg-macros/i9685bis.scala:23:4 -------------------------------------------------------- -23 | 1.asdf // error - | ^^^^^^ - | value asdf is not a member of Int, but could be made available as an extension method. - | - | The following import might make progress towards fixing the problem: - | - | import foo.Baz.toBaz - | diff --git a/tests/neg-macros/i9685bis.scala b/tests/neg-macros/i9685bis.scala deleted file mode 100644 index 0023d4d719b4..000000000000 --- a/tests/neg-macros/i9685bis.scala +++ /dev/null @@ -1,23 +0,0 @@ -package foo - -import scala.language.implicitConversions - -class Foo - -object Foo: - - inline implicit def toFoo(x: Int): Foo = Foo() - -class Bar - -object Bar: - inline given Conversion[Int, Bar] with - def apply(x: Int): Bar = Bar() - -class Baz - -object Baz: - transparent inline implicit def toBaz(x: Int): Baz = Baz() - -object Usage: - 1.asdf // error From 5bc43d317cd571eac3b6c1a2c5ae41c1a693678f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 11 Mar 2024 15:46:28 +0100 Subject: [PATCH 3/3] Add regression tests for #18123 --- tests/pos/i18123.scala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/pos/i18123.scala diff --git a/tests/pos/i18123.scala b/tests/pos/i18123.scala new file mode 100644 index 000000000000..714850004d2c --- /dev/null +++ b/tests/pos/i18123.scala @@ -0,0 +1,25 @@ +// may not compile anymore in Scala 3.4+ +package pkg + +trait P[+T] + +extension [T](inline parse0: P[T]) + inline def | [V >: T](inline other: P[V]): P[V] = ??? + +extension [T](inline parse0: => P[T]) + inline def rep[V](inline min: Int = 0)(using repeater: Implicits.Repeater[T, V]): P[V] = ??? + +object Implicits: + trait Repeater[-T, R] + object Repeater: + implicit def GenericRepeaterImplicit[T]: Repeater[T, Seq[T]] = ??? + +sealed trait RegexTree +abstract class Node extends RegexTree +class CharClassIntersection() extends Node + +def classItem: P[RegexTree] = ??? +def charClassIntersection: P[CharClassIntersection] = ??? + +def x = + (charClassIntersection.rep() | classItem.rep())