-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
For some reason cstring can implicitly convert to pointer but not ptr char, and that's true for all backends. Converting to pointer in JS though is broken because of the following:
Example
let x: pointer = cstring"abcd"
let y = x
discard yCurrent Output
Generated codegen:
var x_622003 = "abcd";
var y_622004 = [x_622003[0], x_622003[1]];Nim treats the cstring like it's a pointer already and tries to copy instead of converting. This will break, ["a", "b"] is not a valid pointer.
Expected Output
meaning expected codegen:
var x_622003 = "abcd";
var y_622004 = [x_622003, 0];Additional Information
["abcd", 0]being a valid pointer is another question, since JS cstrings are immutable, but this already happens when used like this:
var x = cstring"abcd"
let y = addr x[0]
discard yy in this case is ["abcd", 0]. A good solution to this would be to make cstrings in JS unsafe addresses like let variables, but the same would have to apply to the implicit pointer conversion.
$ nim -v
Nim Compiler Version 1.2.0