Skip to content

Implicit values (types) defined in a for comprehension cannot be properly used right after #15526

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

Closed
kovacshuni opened this issue Jun 26, 2022 · 3 comments

Comments

@kovacshuni
Copy link

Compiler version

3.1.1, 3.1.2

Minimized code

How do you fetch an implicit value in a for comprehension, when its type is parameterized?

for
  o               <- Option("line just to make for comprehension start")
  given Int       = 2
  a               = implicitly[Int] // error: same kind as below
  given List[Int] = List(1, 2, 3)
  b               = implicitly[List[Int]] // error: no implicit argument of type List[Int] was found for parameter e of method implicitly in object Predef
yield ()

Output

no implicit argument of type List[Int] was found for parameter e of method implicitly in object Predef

Expectation

For comprehensions to work cleanly with givens, whether they are defined by a <- or a =.

Would be really great if this worked as implicits and composing dependencies in for comprehensions is fundamental in the tagless final style of coding. Basically the initial part of the application, defining the components makes use of this.

Workaround

But if I insert a dummy line in between the declaration and the usage, it works:

for
  o               <- Option("line just to make for comprehension start")
  given List[Int] = List(1, 2, 3)
  p               <- Option("dummy")
  b               = implicitly[List[Int]] // works
yield ()
@kovacshuni kovacshuni added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 26, 2022
@bishabosha
Copy link
Member

I think this was fixed by #12646, could you see if it works on 3.2.0-RC1?

@kovacshuni
Copy link
Author

Yes, positive.

@kovacshuni
Copy link
Author

Thank you for confirming / taking a look.

@griggt griggt added stat:duplicate and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants