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

shouldn't this re-binding be an error? #1707

Open
shriram opened this issue Sep 18, 2023 · 3 comments
Open

shouldn't this re-binding be an error? #1707

shriram opened this issue Sep 18, 2023 · 3 comments

Comments

@shriram
Copy link
Member

shriram commented Sep 18, 2023

If I write

S = 2
S = 3

I get a name binding conflict error.

However, if I write

import sets as S
S = 2

there is no error, and S is bound to 2. Indeed, in this program

import sets as S
S = 2
S = 3

only the two S = lines produce an error.

I feel like once S is bound by import, re-binding it should produce an error?

(I was tripped up by it because a student asked a question about import and I initially wrote "Pyret will make sure that S is not bound to anything else, and S.foo will …", and then checked and found that that's not actually true. It seems like a thing we would want to be able to say?)

@jpolitz
Copy link
Member

jpolitz commented Sep 18, 2023

Typically we haven't reported binding errors for shadowing across namespaces. Pyret has three – values, types, and modules (and arguably datatypes but that's basically just types).

So you can bind all of:

import lists as L
type L = List
L = list

It actually used to be the case that the as L was in the values namespace; after the module system updates module names got their own namespace (which is good for all kinds of other reasons). So I think (without firing up an old version to test) that this would have been an error ~3 years ago. Since the beginning, the type and value bindings could co-exist; we just don't notice it much because values are typically lowercase and types uppercase so convention separates them.

@jpolitz
Copy link
Member

jpolitz commented Sep 19, 2023

@blerner do we want to spec this as an error? I could go either way. It's not technically backwards compatible with code written since module system updates.... but also I can't see it biting many people, and I could see the argument that modules regressed this behavior.

@blerner
Copy link
Member

blerner commented Sep 19, 2023

I'm torn. I don't see any internally consistent middle ground between having three namespaces or having only one: if module imports ought to conflict with both type and value definitions... then shouldn't types and values collide?

I'm fine keeping it as three separate namespaces, it seems more internally consistent to me.

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