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

parser: check for module globals #10668

Closed

Conversation

shadowninja55
Copy link
Member

@shadowninja55 shadowninja55 commented Jul 5, 2021

this pr ensures that patterns like:

import os
os.foo := 0

are checked by the parser. related to #10658.

@JalonSolov
Copy link
Contributor

That example is perfectly valid in a script-mode file.

@JalonSolov JalonSolov closed this Jul 5, 2021
@shadowninja55
Copy link
Member Author

shadowninja55 commented Jul 5, 2021

That example is perfectly valid in a script-mode file.

but it's assigning to a global, it should require -enable-globals, no? i understand it might be used but it is still a global, that's why i added the pref check.

@shadowninja55 shadowninja55 reopened this Jul 5, 2021
@JalonSolov
Copy link
Contributor

Sorry - didn't mean to close it.

I don't know how that works. I've managed to avoid globals so far.

If you are correct, though, the error message needs to be changed.

if lx.mod == 'main' && '.' in lx.name {
lx_mod := lx.name.all_before('.')
if lx_mod in p.table.imports && !p.pref.enable_globals {
return p.error_with_pos('use `v -enable-globals ...` to enable globals',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "cannot modify globals unless you enable them with the -enable-globals option"

@shadowninja55
Copy link
Member Author

Sorry - didn't mean to close it.

I don't know how that works. I've managed to avoid globals so far.

If you are correct, though, the error message needs to be changed.

no worries. it actually seems v treats it as a scoped variable so i guess it's fine. i do think this needs to be cleared up though because to the average person it would look like a global.

@shadowninja55
Copy link
Member Author

i'll leave this to someone else. it seems in these examples os.foo is a local variable. there is still an issue where the usage of this variable is not traced, but that should be a separate pr.

@shadowninja55 shadowninja55 deleted the check-module-globals branch July 6, 2021 15:22
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

Successfully merging this pull request may close these issues.

None yet

2 participants