Skip to content
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

Tweak convertible implicits fix #18727

Merged
merged 1 commit into from
Nov 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ trait Implicits:
&& !to.isError
&& !ctx.isAfterTyper
&& ctx.mode.is(Mode.ImplicitsEnabled)
&& from.widen.isValueType
&& from.isValueType
&& ( from.isValueSubType(to)
|| inferView(dummyTreeOfType(from), to)
(using ctx.fresh.addMode(Mode.ImplicitExploration).setExploreTyperState()).isSuccess
Expand Down Expand Up @@ -982,7 +982,7 @@ trait Implicits:
.filter { imp =>
!isImplicitDefConversion(imp.underlying)
&& imp.symbol != defn.Predef_conforms
&& viewExists(imp, fail.expectedType)
&& viewExists(imp.underlying.resultType, fail.expectedType)
}
else
Nil
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i16453b1.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- [E172] Type Error: tests/neg/i16453b1.scala:11:19 -------------------------------------------------------------------
11 | val ko = get[Int] // error
| ^
|No given instance of type Ctx => Option[Int] was found for parameter fn of method get
|
|Note: implicit conversions are not automatically applied to arguments of using clauses. You will have to pass the argument explicitly.
|The following implicits in scope can be implicitly converted to Ctx => Option[Int]:
|- final lazy given val foo: Ctx => Int
12 changes: 12 additions & 0 deletions tests/neg/i16453b1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.language.implicitConversions

sealed trait Ctx
given ct[T]: Conversion[Ctx => T, Ctx => Option[T]] = fn => fn.andThen(Option.apply)

def get[T](using fn: Ctx => Option[T]): Option[T] = ???

def Test = {
given foo: (Ctx => Int) = _ => 42
val ok = get[Int](using summon[Ctx => Int])
val ko = get[Int] // error
}
8 changes: 8 additions & 0 deletions tests/neg/i16453b2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- [E172] Type Error: tests/neg/i16453b2.scala:11:19 -------------------------------------------------------------------
11 | val ko = get[Int] // error
| ^
|No given instance of type Ctx => Option[Int] was found for parameter fn of method get
|
|Note: implicit conversions are not automatically applied to arguments of using clauses. You will have to pass the argument explicitly.
|The following implicits in scope can be implicitly converted to Ctx => Option[Int]:
|- final given def foo2[A]: Ctx => Int
12 changes: 12 additions & 0 deletions tests/neg/i16453b2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.language.implicitConversions

sealed trait Ctx
given ct[T]: Conversion[Ctx => T, Ctx => Option[T]] = fn => fn.andThen(Option.apply)

def get[T](using fn: Ctx => Option[T]): Option[T] = ???

def Test = {
given foo2[A]: (Ctx => Int) = _ => 42
val ok = get[Int](using summon[Ctx => Int])
val ko = get[Int] // error
}