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 builder error #19458

Closed
Eliyaan opened this issue Sep 27, 2023 · 6 comments · Fixed by #19460
Closed

C builder error #19458

Eliyaan opened this issue Sep 27, 2023 · 6 comments · Fixed by #19460
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture.

Comments

@Eliyaan
Copy link
Contributor

Eliyaan commented Sep 27, 2023

Describe the bug

It outputs a c error when I run it (but in my actual code, without the [direct_array_access] it works perfectly fine.

Reproduction Steps

struct Bar {
	f    []fn (f64) f64
}

[direct_array_access]
fn (b Bar) foo() {
	b.f[0](0)
}

Current Behavior

==================
C:/Users/PACHECON/AppData/Local/Temp/v_0/example.9219600577512629630.tmp.c:6791: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/PACHECON/AppData/Local/Temp/v_0/example.9219600577512629630.tmp.c:12557: error: cannot convert 'void *' to 'struct array'
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error. This should never happen.

V version

V 0.4.1 8f69bd1

Environment details (OS name and version, etc.)

PS C:\Users\PACHECON_cv\spartlink_nns> v doctor
V full version: V 0.4.1 7bfb35d.8f69bd1
OS: windows, Microsoft Windows 10 ducation v19045 64 bits

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.

@Eliyaan Eliyaan added the Bug This tag is applied to issues which reports bugs. label Sep 27, 2023
@JalonSolov
Copy link
Contributor

Yes, V should give a nicer error message for this.

However, you definitely have an error in your code.

You never set up the []fn array, so there are no functions to call, and you would basically get an illegal access error if it actually compiled and you tried to run it.

@Eliyaan
Copy link
Contributor Author

Eliyaan commented Sep 27, 2023

This code is only a reduced version of a functional code, on my project it only breaks when I add [direct_array_access] but without, it runs perfectly fine (because I have things in my array and stuff) but there it isn't executed but still outputs an error (and in my actual code it outputs an errror before anything gets executed) (This code is only a minimum reproduction of the bug).

@Air-EL
Copy link

Air-EL commented Sep 28, 2023

if use the code below, it outputs errors.

struct Bar {
mut:
 f []fn (f64) f64
}
// without [direct_array_access], the code is working.
[direct_array_access]
fn (b Bar) foo() {
 b.f[0](0)
}
fn add_one(n f64) f64 {
 println('numis: ${n}\naddoneis: ${n + 1}')
 return n + 1
}
fn main() {
 mut bar := Bar{}
 bar.f << add_one
 bar.foo()
}

errors:

F:\0dxl\project\DayDayUp\test>v test.v
==================
C:\Users\Administrator.DESKTOP-8RCLOHN\AppData\Local\Temp\v_0\test.605396499273773818.tmp.c: In function 'main__Bar_foo':
C:\Users\Administrator.DESKTOP-8RCLOHN\AppData\Local\Temp\v_0\test.605396499273773818.tmp.c:12535:51: error: incompatible type for argument 1 of 'array_get'
12535 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ~~~^~~~~
      | |
      | voidptr {aka void *}
C:\Users\Administrator.DESKTOP-8RCLOHN\AppData\Local\Temp\v_0\test.605396499273773818.tmp.c:6102:41: note: expected 'array' but argument is of type 'voidptr' {aka 'void *'}
 6102 | VV_LOCAL_SYMBOL voidptr array_get(array a, int i) {
      | ~~~~~~^
C:\Users\Administrator.DESKTOP-8RCLOHN\AppData\Local\Temp\v_0\test.605396499273773818.tmp.c:12535:38: error: too few arguments to function 'array_get'
12535 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ^~~~~~~~~
...
==================
(Use `v -cg` to print the entire error message)
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
F:\test>v -cg test.v
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c: In function 'main__Bar_foo':
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:12537:51: error: incompatible type for argument 1 of 'array_get'
12537 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ~~~^~~~~
      | |
      | voidptr {aka void *}
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:6104:25: note: expected 'array' but argument is of type 'voidptr' {aka 'void *'}
 6104 | voidptr array_get(array a, int i) {
      | ~~~~~~^
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:12537:38: error: too few arguments to function 'array_get'
12537 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ^~~~~~~~~
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:6104:9: note: declared here
 6104 | voidptr array_get(array a, int i) {
      | ^~~~~~~~~
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:12537:63: error: expected ')' before ';' token
12537 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ~ ^
      | )
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:12537:64: error: expected ')' before '}' token
12537 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ~ ^
      | )
12538 | }
      | ~
C:\Users\Administrator\AppData\Local\Temp\v_0\test.8902037882555371595.tmp.c:12537:64: error: expected ';' before '}' token
12537 | ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0);
      | ^
      | ;
12538 | }
      | ~
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang

see error below

C:\Users\Administrator\AppData\Local\Temp\v_0\test.605396499273773818.tmp.c: In function 'main__Bar_foo':
C:\Users\Administrator\AppData\Local\Temp\v_0\test.605396499273773818.tmp.c:12535:51: error: incompatible type for argument 1 of 'array_get'

array_get need 2 params, but 1 given.
and there is lack of 2 ) in the end of expression ((f64 (*) (f64 ))(*(voidptr*)array_get(b.f.data)[0](0)

all these errors may caused by compiler of Vlang when compile attr[direct_array_access]

@Eliyaan
Copy link
Contributor Author

Eliyaan commented Sep 28, 2023

With your code, I dont get the same amout of errors as you.

PS C:\Users\PACHECON\_cv\spartlink_nns> v -cg "c:\Users\PACHECON\_cv\spartlink_nns\example.v"    
C:/Users/PACHECON/AppData/Local/Temp/v_0/example.10584866717599172867.tmp.c:498: warning: WINVER redefined
C:/Users/PACHECON/AppData/Local/Temp/v_0/example.10584866717599172867.tmp.c:6794: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/PACHECON/AppData/Local/Temp/v_0/example.10584866717599172867.tmp.c:12560: error: cannot convert 'void *' to 'struct array'        
builder error:
==================
C error. This should never happen.

@yuyi98
Copy link
Member

yuyi98 commented Sep 28, 2023

struct Bar {
mut:
	f []fn (f64) f64
}

// without [direct_array_access], the code is working.
[direct_array_access]
fn (b Bar) foo() {
	b.f[0](0)
}

fn add_one(n f64) f64 {
	println('numis: ${n}\naddoneis: ${n + 1}')
	return n + 1
}

fn main() {
	mut bar := Bar{}
	bar.f << add_one
	bar.foo()
}

PS D:\Test\v\tt1> v run .       
numis: 0.0
addoneis: 1.0

@Air-EL
Copy link

Air-EL commented Sep 28, 2023

@yuyi98 I try your code, it's work. You are right.

@ArtemkaKun ArtemkaKun added the Build V build error on any OS/CPU architecture. label Sep 28, 2023
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants