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

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

Closed
WojciechMazur opened this issue Dec 1, 2022 · 1 comment
Labels
area:implicits related to implicits good first issue Perfect for someone who wants to get started contributing itype:enhancement Spree Suitable for a future Spree

Comments

@WojciechMazur
Copy link
Contributor

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])
@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 1, 2022
@Kordyjan Kordyjan added area:implicits related to implicits itype:enhancement good first issue Perfect for someone who wants to get started contributing Spree Suitable for a future Spree and removed stat:needs triage Every issue needs to have an "area" and "itype" label itype:bug labels Dec 2, 2022
@WojciechMazur WojciechMazur changed the title Compiler should hint about forbined combining of implicit values search with their conversion Compiler should hint about forbiden combination of implicit values search with their conversion Dec 2, 2022
@SethTisue SethTisue changed the title Compiler should hint about forbiden combination of implicit values search with their conversion Compiler should hint about forbidden combination of implicit values search with their conversion Jan 12, 2023
prolativ added a commit that referenced this issue Feb 1, 2023
…16735)

For fixing #16453.

When an implicit argument of some type `T` is missing, this looks for
all implicit conversions in scope resulting in type `T` and includes a note
that you can't combine implicit values and conversions.
@prolativ
Copy link
Contributor

prolativ commented Feb 1, 2023

Fixed by #16735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits good first issue Perfect for someone who wants to get started contributing itype:enhancement Spree Suitable for a future Spree
Projects
None yet
Development

No branches or pull requests

3 participants