Skip to content

Commit

Permalink
Fix array cannot accepted to get except a number
Browse files Browse the repository at this point in the history
  • Loading branch information
m3m0r7 committed Sep 27, 2023
1 parent 0ea8652 commit db001c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/VM/Core/Runtime/Entity/Array_.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function each(CallInfoInterface $callInfo, ContextInterface $context): Ru
);
}

$object = Number::createBy($symbol[$i]->valueOf())
$object = EntityHelper::createEntityBySymbol($symbol[$i])
->toBeRubyClass()
->setRuntimeContext($executor->context())
->setUserlandHeapSpace($executor->context()->self()->userlandHeapSpace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ public function process(ContextInterface|RubyClassInterface ...$arguments): Proc
$num = $this->getOperandAsNumber();

for ($i = $num->valueOf() - 1; $i >= 0; --$i) {
$entries[$i] = $this->getStackAsNumber()->symbol();
$entries[$i] = $this->getStackAsEntity()->symbol();
}

$this->context->vmStack()->push(
new Operand(
Array_::createBy(array_values($entries))
->toBeRubyClass(),
Array_::createBy(
array_reverse(
array_values($entries),
),
)->toBeRubyClass(),
),
);

Expand Down
23 changes: 23 additions & 0 deletions tests/Version/Ruby3_2/SyntaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,27 @@ public function testSymbol(): void

_, $rubyVMManager->stdOut->readAll());
}

public function testStringArray(): void
{
$rubyVMManager = $this->createRubyVMFromCode(
<<< '_'
%w(foo bar baz).each do | str |
puts str
end
_,
);

$executor = $rubyVMManager
->rubyVM
->disassemble(RubyVersion::VERSION_3_2);

$this->assertSame(ExecutedStatus::SUCCESS, $executor->execute()->executedStatus);
$this->assertSame(<<<'_'
foo
bar
baz

_, $rubyVMManager->stdOut->readAll());
}
}

0 comments on commit db001c0

Please sign in to comment.