vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.82k stars 2.17k forks source link

cgen error when `-g` is used on a program containing an if expression, with comptime if inside its branches #22873

Open spytheman opened 1 day ago

spytheman commented 1 day ago

V doctor:

V full version: V 0.4.8 8ebbace.6e2f2cc
OS: linux, Ubuntu 20.04.6 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/puzzle_vibes
vexe: /home/delian/code/v/v
vexe mtime: 2024-11-16 11:41:36

vroot: OK, value: /home/delian/code/v
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.0
Git vroot status: weekly.2024.46-40-g6e2f2cc3
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

What did you do? ./v -g -o vdbg cmd/v && ./vdbg /tmp/bug.v

import os

struct TaggedSource {}

type SumType = TaggedSource | string | int

fn main() {
    f()
}

fn f() {
    source := SumType('some_nonexisting_file')
    dump(source)
    path := match source {
        string {
            $if android && !termux {
                if !source.starts_with('/') {
                    'file://${source}'
                } else {
                    eprintln('${@STRUCT}.${@FN}: error converting "${source}" (Android) to `fetch` compatible source"')
                    ''
                }
            } $else {
                if os.is_file(source) {
                    'file://${source}'
                } else {
                    eprintln('${@STRUCT}.${@FN}: error converting "${source}" to `fetch` compatible source"')
                    ''
                }
            }
        }
        TaggedSource {
            $if android && !termux {
                if !source.str().starts_with('/') {
                    'file://${source.str()}'
                } else {
                    eprintln('${@STRUCT}.${@FN}: error converting "${source.str()}" (Android) to `fetch` compatible source"')
                    ''
                }
            } $else {
                if os.is_file(source.str()) {
                    'file://${source.str()}'
                } else {
                    eprintln('${@STRUCT}.${@FN}: error converting "${source.str()}" to `fetch` compatible source"')
                    ''
                }
            }
        }
        else {
            ''
        }
    }
    dump(path)
}

What did you expect to see?

A compiled program, even with -g (it compiles without it)

What did you see instead?

[/tmp/bug.v:13] source: SumType('some_nonexisting_file')
.f: error converting "some_nonexisting_file" to `fetch` compatible source"
[/tmp/bug.v:53] path: 

[!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.

Huly®: V_0.6-21316

spytheman commented 1 day ago

With -g:

#1 13:54:59 ^ master /v/puzzle_vibes>v -g  /tmp/bug.v
/tmp/v_1000/../../../../../../tmp/bug.v:17: error: expression expected before '}'