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

Shadowing warning doesn't apply to let bindings #1369

Closed
starper opened this issue Aug 12, 2015 · 6 comments
Closed

Shadowing warning doesn't apply to let bindings #1369

starper opened this issue Aug 12, 2015 · 6 comments
Assignees
Milestone

Comments

@starper
Copy link

starper commented Aug 12, 2015

This code does not throw "Duplicate value declaration" (or any other) error:

foo :: forall e. Eff (console :: CONSOLE | e) Unit
foo = do
  a <- pure 5
  log $ "a is " ++ (show a)
  a <- pure 10
  log $ "a is " ++ (show a)
  let a = 5
  log $ "a is " ++ (show a)
  let a = 10
  log $ "a is " ++ (show a)

And if you run it you'll see:

a is 5
a is 10
a is 5
a is 10
@michaelficarra
Copy link
Contributor

This is shadowing, just as is allowed in regular let bindings.

-- x is 1
x :: Int
x = let a = 0 in let a = 1 in a

@starper
Copy link
Author

starper commented Aug 12, 2015

So this is supposed to be this way? Sorry then.

@garyb
Copy link
Member

garyb commented Aug 12, 2015

There probably should be a shadowed variable warning, but yeah it's not an error.

@starper
Copy link
Author

starper commented Aug 12, 2015

I guess I should have asked in IRC before creating an issue :) I think warning will be great.

@paf31 paf31 added this to the 0.8.0 milestone Aug 12, 2015
@paf31 paf31 changed the title No "Duplicate value declaration" error Shadowing warning doesn't apply to let bindings Aug 12, 2015
@mjgpy3
Copy link
Contributor

mjgpy3 commented Aug 12, 2015

When I run:

module Lets where

b = let a = 4
    in let a = 5
       in a

I get:

Compiling Lets
Warning found:
Warning in module Lets:
Warning at /home/michael/dev/contrib/purescript/Lets.purs line 3, column 1 - line 5, column 11:
  Name 'a' was shadowed.
See https://github.com/purescript/purescript/wiki/Error-Code-ShadowedName for more information, or to contribute content related to this error.

This seems to imply the issue is in desugaring and not lets in general

@paf31 paf31 self-assigned this Nov 8, 2015
@paf31
Copy link
Contributor

paf31 commented Nov 11, 2015

The issue is that linting happens before desugaring, and do notation isn't handled by the linter. But even if it were, everythingWithContext does the wrong thing, since it doesn't pass state between do notation nodes.

@paf31 paf31 closed this as completed in e7430f7 Nov 23, 2015
paf31 added a commit that referenced this issue Nov 23, 2015
Fix #1185, fix #1369, add everythingWithScope traversal to correct some scoping issues.
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

5 participants