-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
jsgen: cannot assign unsafe nil values (fix #24407) #24438
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
jsgen: cannot assign unsafe nil values (fix #24407) #24438
Conversation
|
Connected to Huly®: V_0.6-22809 |
vlib/v/gen/js/tests/unsafe.v
Outdated
| // Basic test of assigning nil to a string pointer | ||
| mut a := &string('hi!') |
There was a problem hiding this comment.
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
vlib/v/gen/js/tests/unsafe.v
Outdated
| unsafe { | ||
| a = nil | ||
| } | ||
| JS.console.log(a) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
vlib/v/gen/js/tests/unsafe.v
Outdated
| ptrs[0] = &string('hello') | ||
| ptrs[1] = &string('world') |
There was a problem hiding this comment.
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
|
Closed because of #24458 . |
Fixes #24407, #24436