Skip to content

Followup fix to transparent inline conversion #18130

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

Merged
merged 1 commit into from
Jul 10, 2023
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
20 changes: 17 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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

Expand Down Expand Up @@ -113,9 +114,22 @@ 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) && meth.is(Transparent)) {
constrainResult(mt, wildApprox(pt))
true
if (Inlines.isInlineable(meth)) {
// Stricter behaviour in 3.4+: do not apply `wildApprox` to non-transparent inlines
if (Feature.sourceVersion.isAtLeast(SourceVersion.future)) {
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/lampepfl/dotty/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
}
}
else constrainResult(mt, pt)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class BootstrappedOnlyCompilationTests {
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
aggregateTests(
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
compileFilesInDir("tests/neg-inlines-strict", defaultOptions.and("-source", "future")),
compileFile("tests/pos-macros/i9570.scala", defaultOptions.and("-Xfatal-warnings")),
compileFile("tests/pos-macros/macro-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
compileFile("tests/pos-macros/macro-experimental.scala", defaultOptions.and("-Yno-experimental")),
Expand Down
9 changes: 9 additions & 0 deletions tests/neg-inlines-strict/i9685bis.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- [E008] Not Found Error: tests/neg-inlines-strict/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
|
23 changes: 23 additions & 0 deletions tests/neg-inlines-strict/i9685bis.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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
25 changes: 25 additions & 0 deletions tests/pos-macros/i18123.scala
Original file line number Diff line number Diff line change
@@ -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())