You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When setting a constant with compile time if statements the compiler thinks that the constant is void when used in a function later. And I get a mismatched type error when trying to concat 2 strings.
Expected Behavior
Expected code to compile.
Current Behavior
Code fails compilation with a mismatched type (void and string) error.
Documents/test/main.v:15:13: error: mismatched types `void` and `string`
13 | // works if you add `'' +` before 'color'
14 | val := match salutation {
15 | 'hello' { color + ' some text' }
| ~~~~~~~~~~~~~~~~~~~~
16 | 'goodbyte' { color + ' some other text' }
17 | else { 'invalid' }
Documents/test/main.v:16:16: error: mismatched types `void` and `string`
14 | val := match salutation {
15 | 'hello' { color + ' some text' }
16 | 'goodbyte' { color + ' some other text' }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
17 | else { 'invalid' }
18 | }
Documents/test/main.v:17:10: error: return type mismatch, it should be `void`
15 | 'hello' { color + ' some text' }
16 | 'goodbyte' { color + ' some other text' }
17 | else { 'invalid' }
| ~~~~~~~~~
18 | }
19 | println(val)
Documents/test/main.v:14:5: error: assignment mismatch: 1 variable(s) 0 value(s)
12 | salutation := 'hello'
13 | // works if you add `'' +` before 'color'
14 | val := match salutation {
| ~~
15 | 'hello' { color + ' some text' }
16 | 'goodbyte' { color + ' some other text' }
Documents/test/main.v:19:2: error: `println` can not print void expressions
17 | else { 'invalid' }
18 | }
19 | println(val)
| ~~~~~~~~~~~~
20 | }
Funny thing is: the printing void value error magically disappears if you use this code.
importtermconst (
color=$if windows {
term.bright_cyan('WINDOWS')
} $else {
term.bright_green('UNIX')
}
)
fnmain() {
salutation:='hello'// works if you add `'' +` before 'color'val:=match salutation {
'hello' { ''+ color +' some text' }
'goodbyte' { ''+ color +' some other text' }
else { 'invalid' }
}
println(val)
}
Reproduction Steps
importtermconst (
color=$if windows {
term.bright_cyan('WINDOWS')
} $else {
term.bright_green('UNIX')
}
)
fnmain() {
salutation:='hello'// works if you add `'' +` before 'color'val:=match salutation {
'hello' { color +' some text' }
'goodbyte' { color +' some other text' }
else { 'invalid' }
}
println(val)
}
V full version: V 0.4.0 76b4c92.c862394
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 16 cpus, 64bit, little endian,
getwd: C:\Users\imado
vexe: C:\Users\imado\v\v.exe
vexe mtime: 2023-08-17 20:42:38
vroot: OK, value: C:\Users\imado\v
VMODULES: OK, value: C:\Users\imado\.vmodules
VTMP: OK, value: C:\Users\imado\AppData\Local\Temp\v_0
Git version: git version 2.33.1.windows.1
Git vroot status: weekly.2023.32-71-gc8623943
.git/config present: true
CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.
thirdparty/tcc status: thirdparty-windows-amd64 e90c2620
The text was updated successfully, but these errors were encountered:
Describe the bug
When setting a constant with compile time if statements the compiler thinks that the constant is void when used in a function later. And I get a mismatched type error when trying to concat 2 strings.
Expected Behavior
Expected code to compile.
Current Behavior
Code fails compilation with a mismatched type (void and string) error.
Funny thing is: the printing void value error magically disappears if you use this code.
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.0 76b4c92.c862394
Environment details (OS name and version, etc.)
The text was updated successfully, but these errors were encountered: