From eb38e1f0fc38313ab17969a74664618900ace2e9 Mon Sep 17 00:00:00 2001 From: Julien Richard-Foy Date: Tue, 6 Jun 2023 15:53:42 +0200 Subject: [PATCH] Take into account the result type of inline implicit conversions unless they are transparent Fixes #9685 --- community-build/community-projects/munit | 2 +- community-build/community-projects/specs2 | 2 +- .../dotty/tools/dotc/typer/ProtoTypes.scala | 5 ++-- tests/neg-macros/i9685bis.check | 9 ++++++++ tests/neg-macros/i9685bis.scala | 23 +++++++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tests/neg-macros/i9685bis.check create mode 100644 tests/neg-macros/i9685bis.scala diff --git a/community-build/community-projects/munit b/community-build/community-projects/munit index 92f3ad9e8261..55ae3caecf69 160000 --- a/community-build/community-projects/munit +++ b/community-build/community-projects/munit @@ -1 +1 @@ -Subproject commit 92f3ad9e8261b4c142a551baaf61ef5fed84d36a +Subproject commit 55ae3caecf690c8f1a785d78798955c6042344ca diff --git a/community-build/community-projects/specs2 b/community-build/community-projects/specs2 index 789f23b75db1..71d2510c3d7f 160000 --- a/community-build/community-projects/specs2 +++ b/community-build/community-projects/specs2 @@ -1 +1 @@ -Subproject commit 789f23b75db1cf7961d04468b21a2cc0d7ba32d8 +Subproject commit 71d2510c3d7f90773df3f4d1bd12374a40e50c20 diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index bde279c582e6..8b04ca8dd75b 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -17,6 +17,7 @@ import Inferencing.* import ErrorReporting.* import util.SourceFile import TypeComparer.necessarySubType +import dotty.tools.dotc.core.Flags.Transparent import scala.annotation.internal.sharable @@ -105,14 +106,14 @@ object ProtoTypes { if !res then ctx.typerState.constraint = savedConstraint res - /** Constrain result with special case if `meth` is an inlineable method in an inlineable context. + /** Constrain result with special case if `meth` is a transparent 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)) { + if (Inlines.isInlineable(meth) && meth.is(Transparent)) { constrainResult(mt, wildApprox(pt)) true } diff --git a/tests/neg-macros/i9685bis.check b/tests/neg-macros/i9685bis.check new file mode 100644 index 000000000000..45e7f85aa30d --- /dev/null +++ b/tests/neg-macros/i9685bis.check @@ -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 + | diff --git a/tests/neg-macros/i9685bis.scala b/tests/neg-macros/i9685bis.scala new file mode 100644 index 000000000000..0023d4d719b4 --- /dev/null +++ b/tests/neg-macros/i9685bis.scala @@ -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