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

-vet-unused-variables produces unnecessary errors when variable is used as a index #3943

Open
thetarnav opened this issue Jul 19, 2024 · 8 comments

Comments

@thetarnav
Copy link
Contributor

thetarnav commented Jul 19, 2024

-vet-unused-variables sometimes produces additional errors about unused variables that are unused, although they are used, just in a line with other errors.
This can be confusing and point to a declaration code that is not broken, instead of the actual place that needs correcting.

example:

main :: proc () {
	bar: int
	if non_existing[bar] > 0 {}
}

run:

odin check . -vet-unused-variables

errors:

odin-bug/main.odin(5:2) Error: 'bar' declared but not used 
	bar: int 
	^ 
 
odin-bug/main.odin(6:5) Error: Undeclared name: non_existing 
	if non_existing[bar] > 0 {} 
	   ^~~~~~~~~~~^ 

I would expect to only see the Undeclared name: non_existing error.

odin report

	Odin:    dev-2024-07:ba3d7ba5d
	OS:      Ubuntu 22.04.4 LTS, Linux 6.5.0-44-generic
	CPU:     Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
	RAM:     7631 MiB
	Backend: LLVM 17.0.6
@gingerBill
Copy link
Member

So this is kind of a chicken and egg problem. It's saying it is not used because it technically isn't. But it cannot know that because non_existing doesn't exist.

@thetarnav
Copy link
Contributor Author

thetarnav commented Jul 19, 2024

It can be confusing, which is why I'm reporting it. But I understand that the solution might not be trivial. It actually happens frequently so maybe I'll just get used to it, or stop using the flag.

here is another example:

for val, i in non_existing {
	fmt.println(val, i)
}
odin-bug/main.odin(6:16) Error: Undeclared name: non_existing 
	for val, i in non_existing { 
	              ^~~~~~~~~~~^ 
 
odin-bug/main.odin(7:15) Error: Undeclared name: val 
	fmt.println(val, i) 
	            ^~^ 
 
odin-bug/main.odin(7:20) Error: Undeclared name: i 
	fmt.println(val, i) 
	                 ^ 

@thetarnav thetarnav reopened this Jul 19, 2024
@laytan
Copy link
Collaborator

laytan commented Jul 20, 2024

A possible solution is only showing vet errors when there are 0 actual compiler errors. Is that a good solution? Maybe.

@flysand7
Copy link
Contributor

There is a compiler error though, which is the whole premise of the issue.

@laytan
Copy link
Collaborator

laytan commented Jul 20, 2024

There is a compiler error though, which is the whole premise of the issue.

Which is why a solution is to not show vet errors when there are compiler errors.

In this case it would only show the compiler error about using an undeclared variable, and not the vet errors about an unused variable.

@thetarnav
Copy link
Contributor Author

the errors in my last example are not from vet flags actually, so that's not a full solution.
Also it wouldn't be fun to compile, see few errors, correct them, and compile again only to see more errors that got ignored on the first run.

@laytan
Copy link
Collaborator

laytan commented Jul 20, 2024

I don't think there's an (actionable) solution to this then

@flysand7
Copy link
Contributor

^ I actually like laytan's proposal to only show vet errors only when there are no compiler errors

The more generic version of this problem is showing inter-dependent errors which I don't think can be solved by patching in one or two lines of code, it has to be done on a case-by-case basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants