better-monadic-for
better-monadic-for copied to clipboard
"not found" error when a closure on right side of binding uses `val`
I had a compilation issue in production code today that I couldn't explain, so I reduced it to a minimal case:
import cats.effect.IO
object DeleteMe {
// I am using this - see: https://github.com/oleg-py/better-monadic-for
// addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
def test_OK = {
for {
(a,b,c) <- IO.pure( (1,2,3) )
} yield a+b+c
}
def test_bad = {
for {
(a, b, c) <- IO.pure(11).map{ _ =>
val g = 3 // <--- Any binding here causes compile to fail
(1,2,3)
}
} yield a + b + c // compiler says 'not found' for each of these
}
}
Not sure if I am missing something, but adding that val
binding causes the compile to fail, e.g.
[error] /x/DeleteMe.scala:21:13: not found: value a
[error] } yield a + b + c // compiler says 'not found' for each of these
[error] ^
[error] /x/DeleteMe.scala:21:17: not found: value b
[error] } yield a + b + c // compiler says 'not found' for each of these
[error] ^
[error] /x/DeleteMe.scala:21:21: not found: value c
[error] } yield a + b + c // compiler says 'not found' for each of these
[error] ^
[error] three errors found