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

Poor compilation warning for error propogation in loop #19630

Closed
joshmeranda opened this issue Oct 23, 2023 · 2 comments · Fixed by #19641
Closed

Poor compilation warning for error propogation in loop #19630

joshmeranda opened this issue Oct 23, 2023 · 2 comments · Fixed by #19641
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Nicer V Errors Bugs/feature requests, related to improving V error messages. Result Type Bugs/feature requests, that are related to `!Type`. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@joshmeranda
Copy link

joshmeranda commented Oct 23, 2023

Describe the bug

When using an error propagation in a for loop, I get an error message:

>>> v -cg .
/tmp/v_1001/vsweeper.161389303863868986.tmp.c:12580: error: ')' expected (got "_t1")

This is very unhelpful in debugging and finding the error, and confusing to newcomers to vlang like me. Ideally, we'd get something similar to when trying to use the alternative or for options.

src/main.v:9:24: error: options are not allowed in `for statement increment` (yet)
    7 | fn main() {
    8 |     mut pos := 0
    9 |     for ; pos > 10; pos = foo() or { 6 } {
      |                           ~~~~~
   10 |         println(pos)
   11 |     }

Reproduction Steps

Run each each of the loops below with v -cg .

module main

fn foo() !int {
	return 5
}

fn main() {
	mut pos := 0

	// /tmp/v_1001/vsweeper.161389303863868986.tmp.c:12580: error: ')' expected (got "_t1")
	for ; pos > 10; pos = foo()! {
		println(pos)
	}

	// /tmp/v_1001/vsweeper.7081838145059576425.tmp.c:12579: error: identifier expected
	for pos = foo()!; pos > 10; {
		println(pos)
	}

	// no error
	// for ; pos < foo()!; {
	// 	println(pos)
	// }
}

Expected Behavior

Output the same or similar options are not allowed in 'for statement increment' (yet) as when using error propagation in for loop.

Current Behavior

Compilation fails with warnings:

/tmp/v_1001/vsweeper.161389303863868986.tmp.c:12580: error: ')' expected (got "_t1")

and

/tmp/v_1001/vsweeper.7081838145059576425.tmp.c:12579: error: identifier expected

Possible Solution

Might be possible to handle this the same way v checks for the for i :=0; i < 10; i = foo! { or 5 }

Additional Information/Context

No response

V version

V 0.4.2 65d7126

Environment details (OS name and version, etc.)

V full version: V 0.4.2 7e2d737.65d7126
OS: linux, Ubuntu 22.04.3 LTS
Processor: 16 cpus, 64bit, little endian, 13th Gen Intel(R) Core(TM) i7-1360P

getwd: /home/wrinkle/workspaces/joshmeranda/vsweeper
vexe: /home/wrinkle/workspaces/vlang/v/v
vexe mtime: 2023-10-23 01:52:31

vroot: OK, value: /home/wrinkle/workspaces/vlang/v
VMODULES: OK, value: /home/wrinkle/.vmodules
VTMP: OK, value: /tmp/v_1001

Git version: git version 2.34.1
Git vroot status: weekly.2023.42-28-g65d71269
.git/config present: true

CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

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.

@joshmeranda joshmeranda added the Bug This tag is applied to issues which reports bugs. label Oct 23, 2023
@ArtemkaKun ArtemkaKun added Nicer V Errors Bugs/feature requests, related to improving V error messages. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Result Type Bugs/feature requests, that are related to `!Type`. labels Oct 23, 2023
@HimanshuMahto
Copy link

hey, I'm new to this and would like to contribute to this. Can you please assign me this issue.

@medvednikov
Copy link
Member

@HimanshuMahto sure, you can just submit a PR.

Thanks.

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. Nicer V Errors Bugs/feature requests, related to improving V error messages. Result Type Bugs/feature requests, that are related to `!Type`. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants