-
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.
Tweak convertible implicits fix (#18727)
- Loading branch information
Showing
5 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
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,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 |
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,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 | ||
} |
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,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 |
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,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 | ||
} |