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

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

Open
spytheman opened this issue Nov 16, 2024 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@spytheman
Copy link
Member

spytheman commented Nov 16, 2024

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: 

Huly®: V_0.6-21316

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Nov 16, 2024
@spytheman
Copy link
Member Author

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 '}'

spytheman added a commit to larpon/shy that referenced this issue Nov 16, 2024
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. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

1 participant