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

the error expression evaluated but not used is not reported for arr[i] or { break } inside a for loop #22760

Open
zeozeozeo opened this issue Nov 4, 2024 · 0 comments

Comments

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Nov 4, 2024

V doctor:

V full version: V 0.4.8 5c65e58.3108820
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 10 cpus, 64bit, little endian, 

getwd: C:\Users\user\Downloads
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-11-04 16:24:59

vroot: OK, value: C:\Users\user\Desktop\Code\v
VMODULES: OK, value: C:\Users\user\.vmodules
VTMP: OK, value: C:\Users\user\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.45
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

What did you do?
./v -g -o vdbg cmd/v && ./vdbg test.v

fn main() {
	arr := ["hello", "world"]
	for {
		arr[69] or { break }
	}
	println("0_o")
}

What did you expect to see?

error: expression evaluated but not used

What did you see instead?

================== C compilation error (from tcc): ==============
cc: C:/Users/user/AppData/Local/Temp/v_0/test.01JBW2ABZYYKVJ60MYXSQFBG1J.tmp.c:7156: warning: implicit declaration of function 'tcc_backtrace'
cc: C:/Users/user/AppData/Local/Temp/v_0/test.01JBW2ABZYYKVJ60MYXSQFBG1J.tmp.c:13762: error: ';' expected (got "}")
... (the original output was 3 lines long, and was truncated to 2 lines)
=================================================================
(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 .

Additional information
If another expression or statement is added after the faulty arr[69] or { break } line, the compiler correctly recognizes that the previous expression is unused, however doesn't report the newly inserted one:

fn main() {
	arr := ["hello", "world"]
	for {
		arr[69] or { break }
		1
	}
	println("0_o")
}

errors out with

test.v:4:11: error: expression evaluated but not used
    2 |     arr := ["hello", "world"]
    3 |     for {
    4 |         arr[69] or { break }
      |                 ~~~~~~~~~~~~
    5 |         1
    6 |     }

If expressions like arr[69] or { break } are not supposed to be reported as unused, this should probably be considered a cgen error, as the generated C code does not compile.

This will print 0_o, but should be an error:

fn main() {
    arr := ["hello", "world"]
    for {
        arr[69] or { break }.len
    }
    println("0_o")
}

Huly®: V_0.6-21207

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.

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

No branches or pull requests

1 participant