Skip to content

Commit 3de184c

Browse files
authored
Followup fix to transparent inline conversion (#18130)
Fixes #18123 Follow-up of #17924
1 parent 7ede150 commit 3de184c

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ErrorReporting.*
1818
import util.SourceFile
1919
import TypeComparer.necessarySubType
2020
import dotty.tools.dotc.core.Flags.Transparent
21+
import dotty.tools.dotc.config.{ Feature, SourceVersion }
2122

2223
import scala.annotation.internal.sharable
2324

@@ -113,9 +114,22 @@ object ProtoTypes {
113114
* achieved by replacing expected type parameters with wildcards.
114115
*/
115116
def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean =
116-
if (Inlines.isInlineable(meth) && meth.is(Transparent)) {
117-
constrainResult(mt, wildApprox(pt))
118-
true
117+
if (Inlines.isInlineable(meth)) {
118+
// Stricter behaviour in 3.4+: do not apply `wildApprox` to non-transparent inlines
119+
if (Feature.sourceVersion.isAtLeast(SourceVersion.future)) {
120+
if (meth.is(Transparent)) {
121+
constrainResult(mt, wildApprox(pt))
122+
// do not constrain the result type of transparent inline methods
123+
true
124+
} else {
125+
constrainResult(mt, pt)
126+
}
127+
} else {
128+
// Best-effort to fix https://github.com/lampepfl/dotty/issues/9685 in the 3.3.x series
129+
// while preserving source compatibility as much as possible
130+
val methodMatchedType = constrainResult(mt, wildApprox(pt))
131+
meth.is(Transparent) || methodMatchedType
132+
}
119133
}
120134
else constrainResult(mt, pt)
121135
}

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class BootstrappedOnlyCompilationTests {
109109
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
110110
aggregateTests(
111111
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
112+
compileFilesInDir("tests/neg-inlines-strict", defaultOptions.and("-source", "future")),
112113
compileFile("tests/pos-macros/i9570.scala", defaultOptions.and("-Xfatal-warnings")),
113114
compileFile("tests/pos-macros/macro-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
114115
compileFile("tests/pos-macros/macro-experimental.scala", defaultOptions.and("-Yno-experimental")),
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- [E008] Not Found Error: tests/neg-inlines-strict/i9685bis.scala:23:4 ------------------------------------------------
2+
23 | 1.asdf // error
3+
| ^^^^^^
4+
| value asdf is not a member of Int, but could be made available as an extension method.
5+
|
6+
| The following import might make progress towards fixing the problem:
7+
|
8+
| import foo.Baz.toBaz
9+
|
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package foo
2+
3+
import scala.language.implicitConversions
4+
5+
class Foo
6+
7+
object Foo:
8+
9+
inline implicit def toFoo(x: Int): Foo = Foo()
10+
11+
class Bar
12+
13+
object Bar:
14+
inline given Conversion[Int, Bar] with
15+
def apply(x: Int): Bar = Bar()
16+
17+
class Baz
18+
19+
object Baz:
20+
transparent inline implicit def toBaz(x: Int): Baz = Baz()
21+
22+
object Usage:
23+
1.asdf // error

tests/pos-macros/i18123.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// may not compile anymore in Scala 3.4+
2+
package pkg
3+
4+
trait P[+T]
5+
6+
extension [T](inline parse0: P[T])
7+
inline def | [V >: T](inline other: P[V]): P[V] = ???
8+
9+
extension [T](inline parse0: => P[T])
10+
inline def rep[V](inline min: Int = 0)(using repeater: Implicits.Repeater[T, V]): P[V] = ???
11+
12+
object Implicits:
13+
trait Repeater[-T, R]
14+
object Repeater:
15+
implicit def GenericRepeaterImplicit[T]: Repeater[T, Seq[T]] = ???
16+
17+
sealed trait RegexTree
18+
abstract class Node extends RegexTree
19+
class CharClassIntersection() extends Node
20+
21+
def classItem: P[RegexTree] = ???
22+
def charClassIntersection: P[CharClassIntersection] = ???
23+
24+
def x =
25+
(charClassIntersection.rep() | classItem.rep())

0 commit comments

Comments
 (0)