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

:= is allowed in const declaration #22575

Closed
gechandesu opened this issue Oct 18, 2024 · 6 comments
Closed

:= is allowed in const declaration #22575

gechandesu opened this issue Oct 18, 2024 · 6 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@gechandesu
Copy link
Contributor

gechandesu commented Oct 18, 2024

Describe the bug

V compiles the program with the := sign in the constant declaration. This is inconsistent and confusing. The only option described in the documentation is to use the equal sign.

Reproduction Steps

cnst.v:

module main

const myconst1 = 1
const myconst2 := 2

fn main() {
	println(myconst1)
	println(myconst2)
}
$ v cnst.v
$ ./cnst
1
2

Expected Behavior

Syntax error

Current Behavior

Constants declared with := works fine

Possible Solution

Disallow using := in const

Additional Information/Context

No response

V version

V 0.4.8 5ec9bb5

Environment details (OS name and version, etc.)

V full version: V 0.4.8 5ec9bb5
OS: linux, Linux version 6.6.8-arch1-1 (linux@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000
Processor: 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P

getwd: /home/ge
vexe: /home/ge/.vlang/v
vexe mtime: 2024-10-18 16:32:24

vroot: OK, value: /home/ge/.vlang
VMODULES: OK, value: /home/ge/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.1
Git vroot status: weekly.2024.42-22-g5ec9bb54
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@gechandesu gechandesu added the Bug This tag is applied to issues which reports bugs. label Oct 18, 2024
@Delta456 Delta456 self-assigned this Oct 18, 2024
@Delta456
Copy link
Member

Good find. I will take a look

@JalonSolov
Copy link
Contributor

Yes, it is allowed, but v fmt will remove the :, one of the many changes it can make while trying to make your code more compliant with latest V syntax.

@Delta456
Copy link
Member

Yes, it is allowed, but v fmt will remove the :, one of the many changes it can make while trying to make your code more compliant with latest V syntax.

A warning should be there at least

@JalonSolov
Copy link
Contributor

V should probably warn you about it, but perhaps not... there has been discussion about making := the correct form for const values, to make them move consistent syntax with regular variables.

@JalonSolov
Copy link
Contributor

@medvednikov @spytheman - what do you think? Should V add a warning for this?

@spytheman
Copy link
Member

No, it is a deliberate feature, not a bug.

There should not be a warning, a notice etc at all.

v fmt -w will rewrite it to =, but while you are prototyping, it is very convenient to be able to extract local variables from functions to constants with minimal friction.

@spytheman spytheman closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
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

4 participants