-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
VMsee also `const` labelsee also `const` label
Description
I was trying to create a more efficient string slice type for some parsing I'm doing. I though I had got it to work, but when I ran in in the VM (in a macro) it ended up with different results than when it's run normally:
static:
var
a: ref string
b: ref string
new a
a[] = "Hello world"
b = a
echo a[]
echo b[]
b[5] = 'c'
echo a[]
echo b[]
# Output:
# Hello world
# Hello world
# Hello world
# Hellocworld
var
d: ref string
e: ref string
new d
d[] = "Hello world"
e = d
echo d[]
echo e[]
e[5] = 'c'
echo d[]
echo e[]
# Output:
# Hello world
# Hello world
# Hellocworld
# Hellocworld
Notice how the code in both the static block and below it is identical save for the variable names. But the output is different (second one is expected behaviour were modifying the string through the reference modifies the string for the other reference as well).
Metadata
Metadata
Assignees
Labels
VMsee also `const` labelsee also `const` label