Skip to content

"not found" error when a closure on right side of binding uses val #53

@toby5box

Description

@toby5box

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions