Skip to content

Commit 85908de

Browse files
authored
Tweak convertible implicits fix (#18727)
2 parents bd24735 + a175525 commit 85908de

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Implicits.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ trait Implicits:
852852
&& !to.isError
853853
&& !ctx.isAfterTyper
854854
&& ctx.mode.is(Mode.ImplicitsEnabled)
855-
&& from.widen.isValueType
855+
&& from.isValueType
856856
&& ( from.isValueSubType(to)
857857
|| inferView(dummyTreeOfType(from), to)
858858
(using ctx.fresh.addMode(Mode.ImplicitExploration).setExploreTyperState()).isSuccess
@@ -984,7 +984,7 @@ trait Implicits:
984984
.filter { imp =>
985985
!isImplicitDefConversion(imp.underlying)
986986
&& imp.symbol != defn.Predef_conforms
987-
&& viewExists(imp, fail.expectedType)
987+
&& viewExists(imp.underlying.resultType, fail.expectedType)
988988
}
989989
else
990990
Nil

Diff for: tests/neg/i16453b1.check

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E172] Type Error: tests/neg/i16453b1.scala:11:19 -------------------------------------------------------------------
2+
11 | val ko = get[Int] // error
3+
| ^
4+
|No given instance of type Ctx => Option[Int] was found for parameter fn of method get
5+
|
6+
|Note: implicit conversions are not automatically applied to arguments of using clauses. You will have to pass the argument explicitly.
7+
|The following implicits in scope can be implicitly converted to Ctx => Option[Int]:
8+
|- final lazy given val foo: Ctx => Int

Diff for: tests/neg/i16453b1.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.language.implicitConversions
2+
3+
sealed trait Ctx
4+
given ct[T]: Conversion[Ctx => T, Ctx => Option[T]] = fn => fn.andThen(Option.apply)
5+
6+
def get[T](using fn: Ctx => Option[T]): Option[T] = ???
7+
8+
def Test = {
9+
given foo: (Ctx => Int) = _ => 42
10+
val ok = get[Int](using summon[Ctx => Int])
11+
val ko = get[Int] // error
12+
}

Diff for: tests/neg/i16453b2.check

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E172] Type Error: tests/neg/i16453b2.scala:11:19 -------------------------------------------------------------------
2+
11 | val ko = get[Int] // error
3+
| ^
4+
|No given instance of type Ctx => Option[Int] was found for parameter fn of method get
5+
|
6+
|Note: implicit conversions are not automatically applied to arguments of using clauses. You will have to pass the argument explicitly.
7+
|The following implicits in scope can be implicitly converted to Ctx => Option[Int]:
8+
|- final given def foo2[A]: Ctx => Int

Diff for: tests/neg/i16453b2.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.language.implicitConversions
2+
3+
sealed trait Ctx
4+
given ct[T]: Conversion[Ctx => T, Ctx => Option[T]] = fn => fn.andThen(Option.apply)
5+
6+
def get[T](using fn: Ctx => Option[T]): Option[T] = ???
7+
8+
def Test = {
9+
given foo2[A]: (Ctx => Int) = _ => 42
10+
val ok = get[Int](using summon[Ctx => Int])
11+
val ko = get[Int] // error
12+
}

0 commit comments

Comments
 (0)