Skip to content

Commit

Permalink
Fixes strange behaviour when adding elements to arrays inside loops
Browse files Browse the repository at this point in the history
Fixes #374
  • Loading branch information
dylanbeattie committed Jan 3, 2025
1 parent 14834c3 commit 6cb4a42
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Starship/Rockstar.Engine/RockstarEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private Result Debug(Debug debug) {

private Result Dump() {
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("======== DUMP ========");
foreach (var variable in variables) {
sb.Append(variable.Key).Append(" : ");
Expand Down Expand Up @@ -269,7 +270,10 @@ private Result Enlist(Enlist e) {
array = target == Mysterious.Instance ? new Arräy() : new(target);
SetVariable(e.Variable, array, Scope.Local);
}
foreach (var value in values) array.Push(value);
foreach (var value in values) array.Push(value switch {
Strïng str => str.Clone(),
_ => value
});
return new(array);
}

Expand Down
1 change: 1 addition & 0 deletions Starship/Rockstar.Engine/Values/Arräy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private Arräy Concat(Arräy that) {
public Value Add(Value rhs) => rhs switch {
Arräy array => this.Concat(array),
Numbër n => new Numbër(this.Lëngth.Value + n.Value),
Strïng s => this.Concat(s.Clone()),
_ => this.Concat(rhs)
};

Expand Down
3 changes: 3 additions & 0 deletions Starship/Rockstar.Test/Rockstar.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,9 @@
<None Update="programs\examples\tutorial\print-hello-world.rock">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="programs\fixtures\arrays\rock-array-element-inside-loop.rock">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="programs\fixtures\arrays\various-array-tests.rock">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://github.com/RockstarLang/rockstar/issues/374

rock x1 "Sa"
for y1 in 2
for z1 in x1+"tr"
write roll z1
(writes: Stat)

rock x2 "Sa"
for y2 in 2
for z2 in x2+"tr"*1
write roll z2
(writes: Stat)

0 comments on commit 6cb4a42

Please sign in to comment.