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

Compiler thinks string type is void and produces compile error #19169

Closed
islonely opened this issue Aug 17, 2023 · 0 comments · Fixed by #19179
Closed

Compiler thinks string type is void and produces compile error #19169

islonely opened this issue Aug 17, 2023 · 0 comments · Fixed by #19179
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@islonely
Copy link
Contributor

islonely commented Aug 17, 2023

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.

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.

import term

const (
  color = $if windows {
    term.bright_cyan('WINDOWS')
  } $else {
    term.bright_green('UNIX')
  }
)

fn main() {
  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

import term

const (
  color = $if windows {
    term.bright_cyan('WINDOWS')
  } $else {
    term.bright_green('UNIX')
  }
)

fn main() {
  salutation := 'hello'
  // works if you add `'' +` before 'color'
  val := match salutation {
    'hello' { color + ' some text' }
    'goodbyte' { color + ' some other text' }
    else { 'invalid' }
  }
  println(val)
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.0 76b4c92.c862394

Environment details (OS name and version, etc.)

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
@islonely islonely added the Bug This tag is applied to issues which reports bugs. label Aug 17, 2023
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

Successfully merging a pull request may close this issue.

1 participant