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

Variable overflow when using more than 21 assignments #49

Open
fmonniot opened this issue Oct 20, 2020 · 2 comments
Open

Variable overflow when using more than 21 assignments #49

fmonniot opened this issue Oct 20, 2020 · 2 comments

Comments

@fmonniot
Copy link

Hello there,

First let me thank you for this amazing plugin. Being able to deconstruct values and weaves implicit in for-comprehension is a game changer.

I'm using this plugin to power up the main function of my application. As such, there are a lot of straight assignments (dependencies) in it. I found out that, if there are 22 or more assignments consecutively, the plugin start to reuse variable name in the rewritten code. For example:

def reproducer = for {
    v1 <- Some(1)

    x1 = 1
    x2 = 2
    x3 = 3
    x4 = 4
    x5 = 5
    x6 = 6
    x7 = 7
    x8 = 8
    x9 = 9
    x10 = 10
    x11 = 11
    x12 = 12
    x13 = 13
    x14 = 14
    x15 = 15
    x16 = 16
    x17 = 17
    x18 = 18
    x19 = 19
    x20 = 20
    x21 = 21
    x22 = 22

    v2 <- Some(2)

    useVs = s"$v1$v2"
    useXs = List(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22).mkString
  } yield s"$useVs/$useXs"

will fail to compile with the error

[error] Hello.scala:6:5: not found: value x$1
[error]     v1 <- Some(1)
[error]     ^

For now we bypassed the issue by inserting an artificial <- in the middle of the assignment list, but having to explain why this no-op flatMap is present is a bit confusing :)

22 reminds me of the tuple limit, so maybe there isn't much that can be done to fix this issue. But I though reporting it for others to see would not be a bad idea.

@missingfaktor
Copy link

Just ran into this issue myself. :( Is a fix in progress?

@mr-git
Copy link

mr-git commented Jan 9, 2024

I wound one more "workaround" - add implilcit0(useless: Int) = 42 somewhere in middle of xXX vals - creates virtual "block", which allows to compile code, similar as extra flatMap created by <-

Generated code is using TupleX as "closure" - seems that unwrapping of values has some problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants