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

if ternary: failing to compile #22197

Closed
esquerbatua opened this issue Sep 11, 2024 · 1 comment · Fixed by #22203
Closed

if ternary: failing to compile #22197

esquerbatua opened this issue Sep 11, 2024 · 1 comment · Fixed by #22203
Assignees
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.

Comments

@esquerbatua
Copy link
Contributor

esquerbatua commented Sep 11, 2024

Describe the bug

With an old v ternary operator, with the last version of v it's failing.

Reproduction Steps

fn main() {
	check := true
	mut test := []f64{}
	for i in 0..100 {
		test[i] = if check {
			mut sum := 0.0
			for x in 0..100 {
				if check {
					sum += 1
				}
				if i <= x {
					break
				}
			}
			sum
		} else { 0 }
	}
	println(test)
}

Expected Behavior

Print the result of test

Current Behavior

Failed to compile, C error.

image

Possible Solution

No response

Additional Information/Context

No response

V version

V full version: V 0.4.7 01fd719.6aeef5e

Environment details (OS name and version, etc.)

V full version: V 0.4.7 01fd719.6aeef5e
OS: linux, Ubuntu 24.04.1 LTS
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 7840HS w/ Radeon 780M Graphics

getwd: /home/esquerbatua/git/breakV
vexe: /home/esquerbatua/git/v/v
vexe mtime: 2024-09-11 08:59:35

vroot: OK, value: /home/esquerbatua/git/v
VMODULES: OK, value: /home/esquerbatua/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.0
Git vroot status: weekly.2024.36-36-g6aeef5e4
.git/config present: true

CC version: cc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

@esquerbatua esquerbatua added the Bug This tag is applied to issues which reports bugs. label Sep 11, 2024
@spytheman spytheman added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Sep 11, 2024
@felipensp
Copy link
Member

Reduced test case:

fn main() {
	mut test := []f64{}
	test[0] = if true {
		sum := 0.0
		sum
	} else { 0 }	
	println(test)
}

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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants