v icon indicating copy to clipboard operation
v copied to clipboard

JS backend not supporting [export] attribute

Open radare opened this issue 4 years ago • 3 comments

V version: V 0.2.4 227d12f OS: macOS 10.15

What did you do?

$ cat hello.v
[export: 'TIC']
__global tic = fn (a int) int {
	println('hello')
	return 3
}

fn main() {
 	mut a := 32
 	a += tic(a)
}

What did you expect to see?

I expect to have a global function named TIC externally, but at the same time being usable from inside as in lowercase.

What did you see instead?

the C backend fails because of https://github.com/vlang/v/issues/11373 and https://github.com/vlang/v/issues/11374

and the JS backend just ignores that and doesnt exports TIC.

There are several problems here:

  • GlobalDecl doesnt have [attr]
  • AnonFn doesnt have [attr] either
  • export is not supported in the JS backend

radare avatar Sep 03 '21 09:09 radare

export is not supported in the JS backend

Should be fixed by https://github.com/vlang/v/pull/11377

playXE avatar Sep 03 '21 09:09 playXE

This works in the C backend:

[export: 'TIC']
fn tic(a int) int {
	println('hello')
	return 3
}
fn main() {
 	mut a := 32
 	a += tic(a)
}

spytheman avatar Sep 03 '21 09:09 spytheman

Should be allow exporting global anonymous functions? we can probably forbid this and just suggest to use the [export] attribute instead, which works for C and JS after 11377 gets merged

radare avatar Sep 03 '21 09:09 radare