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

local variable with module before should give a compiler error #10658

Open
danieldaeschle opened this issue Jul 3, 2021 · 11 comments
Open

local variable with module before should give a compiler error #10658

danieldaeschle opened this issue Jul 3, 2021 · 11 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@danieldaeschle
Copy link
Member

danieldaeschle commented Jul 3, 2021

V doctor:

OS: linux, Ubuntu 20.04.2 LTS (WSL 2)
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
CC version: cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

getwd: /home/daniel/Projects/v
vmodules: /home/daniel/.vmodules
vroot: /home/daniel/Projects/v
vexe: /home/daniel/Projects/v/v
vexe mtime: 2021-07-03 14:40:48
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.2 e4d88a5.6454f99

Git version: git version 2.25.1
Git vroot status: weekly.2021.26-39-g6454f998
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 7543de81

What did you do?
v -enable-globals -g -o vdbg cmd/v && vdbg main.v

module main

import mymod

fn main() {
	mymod.msg := 'global variable demo'
	println(mymod.msg)
}

What did you expect to see?

compiler error

What did you see instead?

main.v:6:8: warning: unused variable: `mymod.msg`
    4 | 
    5 | fn main() {
    6 |     mymod.msg := 'global variable demo'
      |           ~~~
    7 |     println(mymod.msg)
    8 | }
@danieldaeschle danieldaeschle added the Bug This tag is applied to issues which reports bugs. label Jul 3, 2021
@JalonSolov
Copy link
Contributor

Is there a typo in your command here, or was it when you actually used it?

It should be -enable-globals.

Also, since you didn't include mymod source, it's hard to tell why that option is needed.

@Gladear
Copy link
Member

Gladear commented Jul 3, 2021

Afaik, it is not allowed to edit a global in another module, is it ?

@JalonSolov
Copy link
Contributor

Globals should be... global. If they're allowed at all.

@danieldaeschle
Copy link
Member Author

Yeah, it was a typo in this issue. But I use the correct -enable-globals.

@shadowninja55
Copy link
Member

this actually isn't a global, v treats it as a local scoped variable.

@danieldaeschle
Copy link
Member Author

I don't get it

@danieldaeschle
Copy link
Member Author

lol, I had a typo :O

@danieldaeschle
Copy link
Member Author

Then this should be a compiler error because this is not a valid variable name.

@danieldaeschle danieldaeschle changed the title use of globals result in warning which should not local variable with module before should give a compiler error Jul 8, 2021
@danieldaeschle
Copy link
Member Author

This issue still exists

@Delta456
Copy link
Member

Delta456 commented Oct 7, 2022

I think this issue can be closed because it now gives the correct error now?

image

@danieldaeschle
Copy link
Member Author

danieldaeschle commented Oct 7, 2022

no, you have to create an mymod module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

5 participants