Skip to content

Compiler should hint about forbidden combination of implicit values search with their conversion #16453

Closed
@WojciechMazur

Description

@WojciechMazur

Compiler version

3.2.1

Minimized code

import scala.language.implicitConversions

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

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

@main def Test = {
  given foo: (Ctx => Int) = _ => 42

  val works = get[Int](using summon[Ctx => Int])
  val fails = get[Int]
}

Output

12 |  val fails = get[Int]
   |                      ^
   |                      No given instance of type Ctx => Option[Int] was found for parameter fn of method get

Expectation

I agree that implicit conversion is dangerous and should be limited.
However, whenever possible, the compiler should hint the user that implicit search no longer allows for chaining conversions.
eg.

```scala
12 |  val fails = get[Int]
   |                      ^
   |                      No given instance of type Ctx => Option[Int] was found for parameter fn of method get
   |                      Ignored implicit Conversion[Ctx => T, Ctx => Option[T]], chaining implicit conversions in no longer allowed in Scala. 
   |                      Use explicit value as a function argument to allow for conversion: 
   |                        get[Int](using summon[Ctx => Int])

Metadata

Metadata

Assignees

No one assigned

    Labels

    SpreeSuitable for a future Spreearea:implicitsrelated to implicitsgood first issuePerfect for someone who wants to get started contributingitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions