-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take into account the result type of inline implicit conversions unle…
…ss they are transparent (#17924) In the first commit, I add a failing test: ~~~ scala import scala.language.implicitConversions class Foo object Foo: inline implicit def toFoo(x: Int): Foo = Foo() object Usage: 1.asdf // error ~~~ We expect that code to not compile but the error reported by the compiler is confusing as it suggests importing `Foo.toFoo` to resolve the compilation error. You can see this in the [test report](https://github.com/lampepfl/dotty/actions/runs/5254687053/jobs/9493612604#step:9:1859). The problem comes from the fact that currently when the compiler checks whether an implicit conversion is applicable to an expression that fails to compile, it does not take into account the expected result type (here, `? { def asdf: ? }`) if the candidate is an `inline` definition. Instead, I believe the expected result type should be taken into account unless the candidate is a `transparent inline`. I make this change in the second commit, which makes the test pass. Fixes #9685
- Loading branch information
Showing
5 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
Submodule specs2
updated
1 files
+3 −6 | core/shared/src/test/scala/org/specs2/matcher/TypecheckSpec.scala |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- [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 | ||
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |