v icon indicating copy to clipboard operation
v copied to clipboard

checker(js): allows you to pass a numeric value to JS.Number without a cast

Open StunxFS opened this issue 6 months ago • 3 comments

Describe the bug

This bug was discovered while developing PR #24653. The checker allows us to pass a numeric value to JS.Number without a prior cast, which leads to an error during JSGen.

Reproduction Steps

$ cat main.v
fn x(a JS.Number) {
	println(a)
}

fn main() {
	d := 1
	x(d)
}

Expected Behavior

I was expecting a compiler error in this case, suggesting the use of JS.Number(d).

Current Behavior

$ v -b js run main.v
jsgen error: could not generate string method voidptr_str for type 'voidptr'

Possible Solution

No response

Additional Information/Context

No response

V version

V latest

Environment details (OS name and version, etc.)

anywhere

[!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.

StunxFS avatar Jun 09 '25 06:06 StunxFS

Connected to Huly®: V_0.6-23034

huly-for-github[bot] avatar Jun 09 '25 06:06 huly-for-github[bot]

I don't think it's a good idea to mix JavaScript primitive types with V. Why would you use JS.Number? Do you have any examples?

gchumillas avatar Jun 10 '25 16:06 gchumillas

@gchumillas

There is no better example than the definitions of JS. interfaces that have methods with arguments of type JS.Number, for example: JS.String

StunxFS avatar Jun 10 '25 22:06 StunxFS