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

Bug with nested letrecs? #84

Open
gmorpheme opened this issue Aug 31, 2020 · 2 comments
Open

Bug with nested letrecs? #84

gmorpheme opened this issue Aug 31, 2020 · 2 comments

Comments

@gmorpheme
Copy link

gmorpheme commented Aug 31, 2020

I think there may be a bug in the handling of nested recursive bindings with embeds... i.e. nested letrecs as in the test I've added here:

curvelogic@39d7c56

(I may be misunderstanding or there may be a way to combine Nest<> or something else to fix this but I'm not seeing it at present.)

When opening the pattern, state depth is not incremented when entering the second scope's pattern so bound variables which actually identify the nested letrec are being looked up in the outer letrec. (Which fails in the test above because there are fewer bindings in the outer letrec than the index of the binding being sought.)

Culprit seems to be a missing .incr() on line 142 of scope.rs. Depth is incremented for unsafe_body but not for unsafe_pattern. I'm not clear in my head yet whether the obvious change of adding the .incr() for the pattern too (like this) is safe or correct but it doesn't seem to break any tests at least.

@gmorpheme
Copy link
Author

gmorpheme commented Aug 31, 2020

The problem example, to save a couple of clicks:

    // expr =
    //      let test = let id = b
    //                      b = \x -> x
    //                  in id
    //      in
    //          test

@gmorpheme
Copy link
Author

gmorpheme commented Aug 31, 2020

Speculative fix was indeed unsafe (counterexample), if for no other reason than it didn't make the compensating change in close_pattern.

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

1 participant