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

Build error - undeclared varaible #21827

Closed
pd-giz-dave opened this issue Jul 8, 2024 · 6 comments · Fixed by #21829
Closed

Build error - undeclared varaible #21827

pd-giz-dave opened this issue Jul 8, 2024 · 6 comments · Fixed by #21829
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.

Comments

@pd-giz-dave
Copy link

pd-giz-dave commented Jul 8, 2024

Describe the bug

Attempt to compile this:

module main
struct Logger {}
fn (l Logger) log(this string) {
	println(this)
}
fn new_logger() &Logger {
	return &Logger{}
}
fn do_log(mut maybe_logr ?&Logger, this string) {
	if logr := maybe_logr {
		logr.log(this)
	}
}
fn bang(mut logr ?&Logger, this string) {
	nested_log := fn [mut logr] (this string) {
		do_log(mut logr, this)
	}
	nested_log(this)
}
fn main()  {
	mut logr := Logger{}
	bang(mut logr, 'bang!')
}

Reproduction Steps

Attempt to compile the code above.
Results in a build error of:

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 .
==================
/tmp/v_1000/main.01J29EYFDM441TFGWJ8E49BHH0.tmp.c:2389: error: 'logr' undeclared

Expected Behavior

It should compile and print "bang!"

Current Behavior

Generates a build error

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.6 66ea826

Environment details (OS name and version, etc.)

dave@dave-mini-pc~/.../fellsafe/v >>> v doctor
V full version: V 0.4.6 294f7e4.66ea826
OS: linux, "EndeavourOS Linux"
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 5800H with Radeon Graphics

getwd: /home/dave/precious/fellsafe/v
vexe: /home/dave/v/v
vexe mtime: 2024-07-08 15:23:28

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

Git version: git version 2.45.2
Git vroot status: weekly.2024.25-79-g66ea8260
.git/config present: true

CC version: cc (GCC) 14.1.1 20240522
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

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.

@pd-giz-dave pd-giz-dave added the Bug This tag is applied to issues which reports bugs. label Jul 8, 2024
@JalonSolov
Copy link
Contributor

If you compile with -g, you see the problem is on this line in the bang() function:

	do_log(mut logr, this)

@JalonSolov JalonSolov added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Jul 8, 2024
@pd-giz-dave
Copy link
Author

pd-giz-dave commented Jul 8, 2024 via email

@JalonSolov
Copy link
Contributor

Yes. My comment was meant as confirmation (that I see the same problem), and something to help whoever tries to fix the problem.

@pd-giz-dave
Copy link
Author

Wow! Great timely response as usual.
How do I get these fixes?
I just did a v up but that didn't do it.

@JalonSolov
Copy link
Contributor

It should have, if v up downloaded the changes. Try doing an explicit git pull then v up again.

@pd-giz-dave
Copy link
Author

When I do this:

dave@dave-mini-pc~/v >>> git pull
From https://github.com/vlang/v
   294f7e416..ca0734743  master     -> origin/master
Already up to date.
dave@dave-mini-pc~/v >>> v up                                                                                                                                                                                                       ±[master]
Updating V...
> git_command: git pull https://github.com/vlang/v master
V is already updated.
Current V version: V 0.4.6 ca07347, timestamp: 2024-07-09 22:10:40 +0300

It says I'm up to date, but when I run the test programs I get this:

dave@dave-mini-pc~/.../fellsafe/v >>> v -g compiler_bugs/main.v
/tmp/v_1000/../../../../../../home/dave/precious/fellsafe/v/compiler_bugs/main.v:46: error: label 'logr' used but not defined
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 .

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

Successfully merging a pull request may close this issue.

3 participants