Skip to content

Commit 1c0906b

Browse files
committed
Test that native arguments get boxed in the called code ref
1 parent dada807 commit 1c0906b

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

t/qast/01-qast.t

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use QAST;
22

3-
plan(149);
3+
plan(164);
44

55
# Following a test infrastructure.
66
sub compile_qast($qast) {
@@ -1899,6 +1899,80 @@ test_qast_result(
18991899
ok($r.twice eq '244', '...and it has the correct value');
19001900
}
19011901
);
1902+
1903+
test_qast_result(
1904+
QAST::CompUnit.new(
1905+
:hll<foo>,
1906+
QAST::Block.new(
1907+
QAST::Op.new(:op<takeclosure>, # needed for JVM
1908+
QAST::Block.new(
1909+
QAST::Var.new(:name<$foo>, :scope<local>, :decl<param>)
1910+
)
1911+
)
1912+
)
1913+
),
1914+
-> $block {
1915+
my int $int := 100;
1916+
my num $num := 10.5;
1917+
my str $str := 'hi';
1918+
1919+
1920+
my $boxed_int := $block($int);
1921+
ok(nqp::istype($boxed_int, $int_boxer), 'the native int passed as arg is boxed to the correct type');
1922+
is(nqp::unbox_i($boxed_int), 100, '...and has the right value');
1923+
1924+
my $boxed_num := $block($num);
1925+
ok(nqp::istype($boxed_num, $num_boxer), 'the native num passed as arg is boxed to the correct type');
1926+
is(nqp::unbox_n($boxed_num), 10.5, '...and has the right value');
1927+
1928+
my $boxed_str := $block($str);
1929+
ok(nqp::istype($boxed_str, $str_boxer), 'the native str passed as arg is boxed to the correct type');
1930+
is(nqp::unbox_s($boxed_str), 'hi', '...and has the right value');
1931+
1932+
my $autoboxed_int := $int;
1933+
my $not_boxed_twice_int := $block($autoboxed_int);
1934+
ok(nqp::eqaddr($autoboxed_int, $not_boxed_twice_int), "alread autoboxed ints don't get boxed twice");
1935+
1936+
my $autoboxed_str := $str;
1937+
my $not_boxed_twice_str := $block($autoboxed_str);
1938+
ok(nqp::eqaddr($autoboxed_str, $not_boxed_twice_str), "alread autoboxed strs don't get boxed twice");
1939+
1940+
my $autoboxed_num := $num;
1941+
my $not_boxed_twice_num := $block($autoboxed_num);
1942+
ok(nqp::eqaddr($autoboxed_num, $not_boxed_twice_num), "alread autoboxed nums don't get boxed twice");
1943+
}
1944+
);
1945+
1946+
test_qast_result(
1947+
QAST::CompUnit.new(
1948+
:hll<foo>,
1949+
QAST::Block.new(
1950+
QAST::Op.new(:op<takeclosure>, # needed for JVM
1951+
QAST::Block.new(
1952+
QAST::Var.new(:name<$foo>, :scope<local>, :decl<param>, :slurpy)
1953+
)
1954+
)
1955+
)
1956+
),
1957+
-> $block {
1958+
my int $int := 100;
1959+
my num $num := 10.5;
1960+
my str $str := 'hi';
1961+
1962+
1963+
my $boxed_int := $block($int)[0];
1964+
ok(nqp::istype($boxed_int, $int_boxer), 'the native int passed as slurpy arg is boxed to the correct type');
1965+
is(nqp::unbox_i($boxed_int), 100, '...and has the right value');
1966+
1967+
my $boxed_num := $block($num)[0];
1968+
ok(nqp::istype($boxed_num, $num_boxer), 'the native num passed as slurpy arg is boxed to the correct type');
1969+
is(nqp::unbox_n($boxed_num), 10.5, '...and has the right value');
1970+
1971+
my $boxed_str := $block($str)[0];
1972+
ok(nqp::istype($boxed_str, $str_boxer), 'the native str passed as slurpy arg is boxed to the correct type');
1973+
is(nqp::unbox_s($boxed_str), 'hi', '...and has the right value');
1974+
}
1975+
);
19021976
}
19031977

19041978
test_qast_result(

0 commit comments

Comments
 (0)