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

bug in return match statement when result/option is involved #22389

Closed
larpon opened this issue Oct 2, 2024 · 1 comment · Fixed by #22404
Closed

bug in return match statement when result/option is involved #22389

larpon opened this issue Oct 2, 2024 · 1 comment · Fixed by #22404
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

@larpon
Copy link
Contributor

larpon commented Oct 2, 2024

Describe the bug

C error when compiling/running the code below.

Reproduction Steps

v run t.v where t.v is:

fn main() {
	install_command(['github:some/thing'], 1) or { panic(err) }
}

pub fn install_command(args []string, verbosity int) ! {
	if args.len == 0 {
		return error('${@FN} requires an argument')
	}
	component := args[0]
	if component.count(':') == 0 {
		return install_command(['github:${component}'], verbosity)
	}
	source := component.all_before(':')
	if source != 'github' {
		return error('${@FN} unknown source `${source}`')
	}
	unit := component.all_after(':')
	return match source {
		'github' {
			install_from_github(unit, verbosity)! // This may be the source of the bug
		}
		else {
			error('${@FN} unknown source `${source}`')
		}
	}
}

fn install_from_github(unit string, verbosity int) ! {
	dump(unit)
}

Expected Behavior

A dump containing github:some/thing

Current Behavior

================== C compilation error (from tcc): ==============
cc: /dev/shm/t.01J96XST9RZXQFCP1MVM8T9YT2.tmp.c:13397: error: declaration of an array of incomplete type elements
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 5e00270

Environment details (OS name and version, etc.)

Linux / EndeavourOS (Arch-based)

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.

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

I've notice compiler c errors, when trying to save to write a lot of return and use something like this for options or results:

return match x {
  one { fn_returning_option() }
  two { none }
  three { fn_returning_string() }
}

The compiler instead don't present the problem when I use return for each case:

match x {
  one { return fn_returning_option() }
  two { return none }
  three { return fn_returning_string() }
}

Seems the compiler has no clue in what type all cases should return, don't know if the list of cases is checked for the "first" one to get the type as when we use an array specifying the first element:

c := [ u8(1), 2, 3 ]

@larpon larpon changed the title bug in return match statement when option is involved bug in return match statement when result/option is involved Oct 2, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants