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

C error from optional anonymous functions and if str_var == 'some_string' comparison #19478

Closed
islonely opened this issue Sep 30, 2023 · 1 comment · Fixed by #19491
Closed
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@islonely
Copy link
Contributor

islonely commented Sep 30, 2023

Describe the bug

Bug is generated when setting an option field that is an anonymous function. The error only appears when using the if statement below. Doing println(value == 'unlimited') works.

Reproduction Steps

// CycleMenuItem is a menu item that can be cycled through by pressing a button.
//
pub struct CycleMenuItem {
mut:
	label  string
	values []string
	on     CycleMenuItemEvents
}

// CycleMenuItemEvents is a set of events that can be invoked by a
// `CycleMenuItem`.
[params]
pub struct CycleMenuItemEvents {
__global:
	click ?fn (string)
	cycle ?fn (string)
}

// CycleMenuItem.new creates a new `CycleMenuItem` with the given label, values,
// and function to invoke when the item is selected.
[inline]
pub fn CycleMenuItem.new(label string, values []string, events CycleMenuItemEvents) CycleMenuItem {
	return CycleMenuItem{
		label: label
		values: values
		on: events
	}
}

fn main() {
	_ := CycleMenuItem.new('FPS', ['30', '60', '90', '120', '144', '165', 'unlimited'],
		click: fn (value string) {
			if value == 'unlimited' {
			}
		}
	)
}

Expected Behavior

Expected code to compile with no output.

Current Behavior

C:/Users/imado/AppData/Local/Temp/v_0/test.4352526411636125798.tmp.c:500: warning: WINVER redefined
C:/Users/imado/AppData/Local/Temp/v_0/test.4352526411636125798.tmp.c:6816: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/imado/AppData/Local/Temp/v_0/test.4352526411636125798.tmp.c:12588: error: cannot convert 'typedef struct _option_anon_fn_string' to 'int'
builder error: 
==================
C error. This should never happen.

Possible Solution

No response

Additional Information/Context

No response

V version

V full version: V 0.4.1 68cbf27.24278d8

Environment details (OS name and version, etc.)

V full version: V 0.4.1 68cbf27.24278d8
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 16 cpus, 64bit, little endian, 

getwd: C:\frostbyte
vexe: C:\Users\imado\v\v.exe
vexe mtime: 2023-09-29 19:06:29

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

Git version: git version 2.33.1.windows.1
Git vroot status: weekly.2023.39-20-g24278d82 (1 commit(s) behind V master)
.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 e90c2620

Note

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@islonely islonely added the Bug This tag is applied to issues which reports bugs. label Sep 30, 2023
@ArtemkaKun ArtemkaKun added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Build V build error on any OS/CPU architecture. labels Sep 30, 2023
@JalonSolov
Copy link
Contributor

Latest V gives a different error:

/tmp/v_1000/bug.9210805605769130305.tmp.c:12475: error: 'anon_fn_' undeclared

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. Build V build error on any OS/CPU architecture. 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