Closed gechandesu closed 1 week ago
Good find. I will take a look
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.
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
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.
@medvednikov @spytheman - what do you think? Should V add a warning for this?
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.
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:
Expected Behavior
Syntax error
Current Behavior
Constants declared with
:=
works finePossible Solution
Disallow using
:=
in constAdditional 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