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 with anonymous functions #23170

Closed
islonely opened this issue Dec 15, 2024 · 4 comments · Fixed by #23175 or #23179
Closed

C error with anonymous functions #23170

islonely opened this issue Dec 15, 2024 · 4 comments · Fixed by #23175 or #23179
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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@islonely
Copy link
Contributor

islonely commented Dec 15, 2024

Describe the bug

C error is produced when using anonymous functions in a structure. It used to compile in the past. Breaking changes make me sad :(

Reproduction Steps

v run client on this repo:
https://github.com/islonely/shattlebip

Expected Behavior

Expected code to compile and run.

Current Behavior

C error being spit out.

================== C compilation error (from cc): ==============
cc: /tmp/v_501/client.01JF462PTRT83BEA41YTKEJHHB.tmp.c:13151:943: warning: braces around scalar initializer [-Wbraced-scalar-init]
cc: /tmp/v_501/client.01JF462PTRT83BEA41YTKEJHHB.tmp.c:13153:36: error: incompatible function pointer types initializing 'anon_fn_voidptr' (aka 'void (*)(void *)') with an expression of type 'void (main__App *)' (aka 'void (struct main__App *)') [-Wincompatible-function-pointer-types]
cc:  13153 |         _option_ok(&(anon_fn_voidptr[]) { main__frame }, (_option*)(&_t1), sizeof(anon_fn_voidptr));
cc:        |                                           ^~~~~~~~~~~
cc: /tmp/v_501/client.01JF462PTRT83BEA41YTKEJHHB.tmp.c:13155:52: error: incompatible function pointer types initializing 'anon_fn_term__ui__event_voidptr' (aka 'void (*)(struct term__ui__Event *, void *)') with an expression of type 'void (term__ui__Event *, main__App *)' (aka 'void (struct term__ui__Event *, struct main__App *)') [-Wincompatible-function-pointer-types]
cc:  13155 |         _option_ok(&(anon_fn_term__ui__event_voidptr[]) { main__event }, (_option*)(&_t2), sizeof(anon_fn_term__ui__event_voidptr));
cc:        |                                                           ^~~~~~~~~~~
cc: /tmp/v_501/client.01JF462PTRT83BEA41YTKEJHHB.tmp.c:13472:34: error: no member named '_v_do' in 'struct main__MenuItem'; did you mean '__v_do'?
cc:  13472 |                 main__Menu_selected(app->menu)._v_do();
cc:        |                                                ^~~~~
cc:        |                                                __v_do
cc: /tmp/v_501/client.01JF462PTRT83BEA41YTKEJHHB.tmp.c:2149:11: note: '__v_do' declared here
... (the original output was 15 lines long, and was truncated to 12 lines)
================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 2911f29.9e71e32

Environment details (OS name and version, etc.)

V full version: V 0.4.8 2911f29.9e71e32
OS: macos, macOS, 15.1.1, 24B91
Processor: 8 cpus, 64bit, little endian, Apple M3

getwd: /Users/adamoates/Documents/shattlebip
vexe: /Users/adamoates/v/v
vexe mtime: 2024-12-15 03:00:13

vroot: OK, value: /Users/adamoates/v
VMODULES: OK, value: /Users/adamoates/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.49-86-g9e71e324
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.4)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

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.

Huly®: V_0.6-21608

@islonely islonely added the Bug This tag is applied to issues which reports bugs. label Dec 15, 2024
@felipensp
Copy link
Member

felipensp commented Dec 15, 2024

Breaking changes make me sad :(

We need more tests to avoid it. :-)

@felipensp felipensp self-assigned this Dec 15, 2024
@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Dec 15, 2024
@islonely
Copy link
Contributor Author

This fix does not resolve the first two errors listed in the original post. After updating to this commit I still get these two:

================== C compilation error (from cc): ==============
cc: /tmp/v_501/client.01JF6EHPT4RX22M81XCT0NS52Z.tmp.c:13151:943: warning: braces around scalar initializer [-Wbraced-scalar-init]
cc: /tmp/v_501/client.01JF6EHPT4RX22M81XCT0NS52Z.tmp.c:13153:36: error: incompatible function pointer types initializing 'anon_fn_voidptr' (aka 'void (*)(void *)') with an expression of type 'void (main__App *)' (aka 'void (struct main__App *)') [-Wincompatible-function-pointer-types]
cc:  13153 |         _option_ok(&(anon_fn_voidptr[]) { main__frame }, (_option*)(&_t1), sizeof(anon_fn_voidptr));
cc:        |                                           ^~~~~~~~~~~
cc: /tmp/v_501/client.01JF6EHPT4RX22M81XCT0NS52Z.tmp.c:13155:52: error: incompatible function pointer types initializing 'anon_fn_term__ui__event_voidptr' (aka 'void (*)(struct term__ui__Event *, void *)') with an expression of type 'void (term__ui__Event *, main__App *)' (aka 'void (struct term__ui__Event *, struct main__App *)') [-Wincompatible-function-pointer-types]
cc:  13155 |         _option_ok(&(anon_fn_term__ui__event_voidptr[]) { main__event }, (_option*)(&_t2), sizeof(anon_fn_term__ui__event_voidptr));
cc:        |                                                           ^~~~~~~~~~~
cc: 1 warning and 2 errors generated.
================================================================

@felipensp
Copy link
Member

Oh It fixes on tcc for running client.v I havent tried to run It on another compiler.

@spytheman
Copy link
Member

@islonely please check with latest V.

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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
4 participants