V: Compiler error:"mismatched types `string` and `&string`"???

Created on 31 Aug 2020  路  3Comments  路  Source: vlang/v

V version:
V 0.1.29 cbcba2e
OS:
64-bit Arch Linux, up-to-date

What did you do?

type Foo = int | string
fn main () {
    mut bar := Foo(5)
    match bar {
        int {println("it's an int: $bar")}
        string {println("shouldn't happen")}
    }
    bar = Foo('hello')
    match bar {
        string {println("it's a string: "+bar)}
        int {println("shouldn't happen")}
    }
}

What did you expect to see?
An executable that, when run, prints

It's an int: 5
It's a string: hello

What did you see instead?
The following from the compiler:

dca@franz:~/Software/v_issues$ ../v/v main.v
main.v:10:42: error: mismatched types `string` and `string`
    8 |     bar = Foo('hello')
    9 |     match bar {
   10 |         string {println("it's a string: "+bar)}
      |                                          ^
   11 |         int {println("shouldn't happen")}
   12 |         }
dca@franz:~/Software/v_issues$
Bug

Most helpful comment

Fixed by #6342

All 3 comments

This works. It first references and then deferences it but it shouldn't be the case

type Foo = int | string
fn main () {
    mut bar := Foo(5)
    match bar {
        int {println("it's an int: $bar")}
        string {println("shouldn't happen")}
    }

    bar = Foo('hello')
    match bar {
        string {println("it's a string: "+ *(&bar))}
        int {println("shouldn't happen")}
    }

}

Fixed by #6342

Please re-open if the issue is still valid 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markgraydev picture markgraydev  路  3Comments

clpo13 picture clpo13  路  3Comments

oleg-kachan picture oleg-kachan  路  3Comments

jtkirkpatrick picture jtkirkpatrick  路  3Comments

radare picture radare  路  3Comments