v icon indicating copy to clipboard operation
v copied to clipboard

vsh: Cannot use `os` constants without importing `os`

Open csfore opened this issue 2 years ago • 3 comments

Describe the bug

In a .vsh file, the module os is currently imported with all of the functions being global so you don't need to import it. Using constants from the module, however, does not work without having to import os.

Expected Behavior

I expected println(args) to print the arguments provided

Current Behavior

println(args) currently errors with

test.vsh:1:9: error: undefined ident: `args`
    1 | println(args)
      |         ~~~~

Reproduction Steps

In a .vsh file (or extension-less)

println(args)

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.3 6b20c57.ac381f5

Environment details (OS name and version, etc.)

OS: linux, "Arch Linux"
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 9 5900HX with Radeon Graphics
CC version: cc (GCC) 12.2.1 20230201

getwd: /home/user/Workspaces/V/bug-testing
vmodules: /home/user/.vmodules
vroot: /home/user/v
vexe: /home/user/v/v
vexe mtime: 2023-02-10 21:12:47
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 6b20c57.ac381f5

Git version: git version 2.39.1
Git vroot status: 0.3.3-60-gac381f5e
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

csfore avatar Feb 10 '23 21:02 csfore

? println(os.args)?

changrui avatar Feb 11 '23 10:02 changrui

I am not sure if .vsh files should allow the implicit import of os module variables/constants.

Delta456 avatar Feb 11 '23 11:02 Delta456

? println(os.args)?

This doesn't work.

println(os.args)
test.vsh:1:9: error: undefined ident: `os`
    1 | println(os.args)
      |         ~~

I am not sure if .vsh files should allow the implicit import of os module variables/constants.

Agreed, as it could have unintended consequences, but it should still warn the user that constants are not implicitly imported. (suggesting importing os, maybe?)

csfore avatar Feb 13 '23 14:02 csfore