Skip to content

Conversation

@gchumillas
Copy link
Contributor

@gchumillas gchumillas commented May 8, 2025

Fixes #24407, #24436

@huly-for-github
Copy link

Connected to Huly®: V_0.6-22809

Comment on lines 31 to 32
// Basic test of assigning nil to a string pointer
mut a := &string('hi!')
Copy link
Member

@spytheman spytheman May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should not compile - 'hi' is a string, not a pointer, or a number

unsafe {
a = nil
}
JS.console.log(a)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use println(), unless you are testing JS.console.log() itself.

It is much easier to compare the common behavior of the different backends, if the tests avoid using platform dependent features.

Copy link
Contributor Author

@gchumillas gchumillas May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I used JS.console.log() because println() fails on null values.

I'm going to fix the ticket #24436 in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If assert a == unsafe { nil } works, use that instead of println, until it is fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern is avoiding/minimizing the divergence, between what is allowed in the C and the JS backends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible either :) The following code generates a JS error:

mut a := 'hi!'
mut b := &a
unsafe {
	b = nil
}

// Cannot read properties of null (reading 'valueOf')
assert b == unsafe { nil }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to generate an exception for unsafe { nil }, which states the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is here:
https://github.com/vlang/v/blob/master/vlib/v/gen/js/js.v#L968

It should return nil__ and that constant should be defined somewhere (similar to how none__ was defined).

Please do not merge the current PR. The solution is incomplete.
Work in progress :)

Comment on lines 74 to 75
ptrs[0] = &string('hello')
ptrs[1] = &string('world')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these shouldn't compile as well

@spytheman spytheman marked this pull request as draft May 10, 2025 11:04
@spytheman
Copy link
Member

Closed because of #24458 .

@spytheman spytheman closed this May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jsgen: cannot assign unsafe nil values

3 participants