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

compiler panic when trying to use a C define in an infix expression #22800

Closed
zeozeozeo opened this issue Nov 8, 2024 · 3 comments · Fixed by #22809
Closed

compiler panic when trying to use a C define in an infix expression #22800

zeozeozeo opened this issue Nov 8, 2024 · 3 comments · Fixed by #22809
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

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Nov 8, 2024

V doctor:

V full version: V 0.4.8 5c65e58.8b991b1
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-08 09:01:50

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-32-g8b991b15
.git/config present: true

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

operable program or batch file.


emcc version: shared:INFO: (Emscripten: Running sanity checks)
thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

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

#include <windows.h>

fn main() {
    C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", C.MB_OK | C.MB_ICONINFORMATION)
}

What did you expect to see?

A messagebox saying "Hello, World!" with an info icon

What did you see instead?

unknown function C.MessageBoxA, searching for the C definition in one of the #includes
================ V panic ================
   module: v.ast
 function: default_table_panic_handler()
  message: table.sym: invalid type (typ=ast.Type(0x0 = 0) idx=0). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.

     file: C:/Users/user/Desktop/Code/v/vlib/v/ast/table.v:88
   v hash: 8b991b1
=========================================
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\builtin\builtin.c.v:87: at panic_debug: Backtrace
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\ast\table.v:88: by v__ast__default_table_panic_handler
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\ast\table.v:94: by v__ast__Table_panic
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\ast\table.v:714: by v__ast__Table_sym
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:2571: by v__gen__c__Gen_expr_with_cast
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\infix.v:1163: by v__gen__c__Gen_gen_plain_infix_expr
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\infix.v:58: by v__gen__c__Gen_infix_expr
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:3570: by v__gen__c__Gen_expr
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\fn.v:2672: by v__gen__c__Gen_call_args
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\fn.v:2364: by v__gen__c__Gen_fn_call
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\fn.v:995: by v__gen__c__Gen_call_expr
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:3458: by v__gen__c__Gen_expr
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:2231: by v__gen__c__Gen_stmt
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:1980: by v__gen__c__Gen_stmts_with_tmp_var
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:1857: by v__gen__c__Gen_stmts
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\fn.v:491: by v__gen__c__Gen_gen_fn_decl
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\fn.v:125: by v__gen__c__Gen_fn_decl
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:2248: by v__gen__c__Gen_stmt
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:1980: by v__gen__c__Gen_stmts_with_tmp_var
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:1857: by v__gen__c__Gen_stmts
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:787: by v__gen__c__Gen_gen_file
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\v\gen\c\cgen.v:735: by v__gen__c__cgen_process_one_file_cb
C:/Users/user/AppData/Local/Temp/v_0/../../../../../..C:\Users\user\Desktop\Code\v\vlib\sync\pool\pool.c.v:118: by sync__pool__process_in_thread
C:/Users/user/AppData/Local/Temp/v_0/vdbg.exe.01JC5GXE9N9V9E5XFC88AN90J2.tmp.c:12345: by sync__pool__process_in_thread_thread_wrapper
7ffafd1f7614 : by ???

Additional information
The following works:

#include <windows.h>

fn main() {
    flags := C.MB_OK | C.MB_ICONINFORMATION
    C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", flags)
}

This makes the compiler think you're making an inline sumtype:

#include <windows.h>

fn main() {
    C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", MB_OK | MB_ICONINFORMATION)
}
test.v:4:70: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
    2 |
    3 | fn main() {
    4 |     C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", MB_OK | MB_ICONINFORMATION)
      |                                                                      ~~~~~
    5 | }
    6 |
test.v:4:96: error: unexpected token `)`, expecting `(`
    2 |
    3 | fn main() {
    4 |     C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", MB_OK | MB_ICONINFORMATION)
      |                                                                                                ^
    5 | }
    6 |

This surprisingly works (no C. prefix before MB_OK):

#include <windows.h>

fn main() {
    C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", MB_OK)
}

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-21246

@spytheman
Copy link
Member

Note: it needs passing -experimental too for reproducing the problem with the same example now.

@medvednikov
Copy link
Member

The "surprisingly works" thing has been fixed. A missing check was re-added.

@felipensp felipensp self-assigned this Nov 8, 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. Bug This tag is applied to issues which reports bugs. labels Nov 8, 2024
@zeozeozeo
Copy link
Contributor Author

The "surprisingly works" thing has been fixed. A missing check was re-added.

I can still run this on a190415:

#include <windows.h>

fn main() {
    C.MessageBoxA(unsafe { nil }, c"Hello, World!", c"Hello World!", MB_OK)
}

image

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
Development

Successfully merging a pull request may close this issue.

4 participants