Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #115566] [BUG] Variables declared in quasi blocks don't work in Rakudo

4 views
Skip to first unread message

Carl Mäsak

unread,
Nov 3, 2012, 7:28:48 AM11/3/12
to bugs-bi...@rt.perl.org
# New Ticket Created by "Carl Mäsak"
# Please include the string: [perl #115566]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=115566 >


<jnthn> r: macro infix:<pos-or>(*@asts) is assoc('list') { my $result =
@asts.pop; for @asts.reverse { $result := quasi{ {{{$_}}} > 0 ?? {{{$_}}}
!! {{{$result}}} } }; $result }; sub foo() { say "oops"; 4 }; say -5 pos-or
3 pos-or foo;
<p6eval> rakudo 2bb302: OUTPUT«3␤»
<jnthn> Using two of the month's new features together :P
<masak> that's pretty impressive.
<jnthn> Sadly, fixing the double evaluation exposes a bug.
<jnthn> r: macro infix:<pos-or>(*@asts) is assoc('list') { my $result =
@asts.pop; for @asts.reverse { $result := quasi { my \x = {{{$_}}}; x > 0
?? x !! {{{$result}}} } }; $result }; sub foo() { say "oops"; 4 }; say -5
pos-or 3 pos-or foo;
<p6eval> rakudo 2bb302: OUTPUT«Lexical 'x' not found␤ in at
/tmp/tiE6e4uirM:1␤ in block at /tmp/tiE6e4uirM:1␤␤»
<masak> "the double evaluation"?
<jnthn> masak: It evalutes the macro argument twice.
<jnthn> masak: Because I wrote it that way
<masak> oh!
<masak> (phew)
<jnthn> {{{$_}}} > 0 ?? {{{$_}}} !! ...
<masak> yes, each {{{}}} evaluates once.
<jnthn> And I wanted to just do it once, but when I try to stick it in a
temporary variable, it busts.
<masak> as above. I see.
<masak> maybe declaring variables in quasis doesn't work?
<jnthn> Seems so
<masak> r: macro foo { quasi { my $a = "OH HAI"; say $a } }; foo
<p6eval> rakudo 2bb302: OUTPUT«Cannot assign into a PMCNULL container [...]
* masak submits rakudobug

Christian Bartolomaeus via RT

unread,
Oct 14, 2014, 7:45:47 AM10/14/14
to perl6-c...@perl.org
Just an update: Parrot no longer segfaults, but Moar does:

$ perl6-m -e 'macro foo { quasi { my $a = "OH HAI"; say $a } }; foo'
Segmentation fault

$ perl6-p -e 'macro foo { quasi { my $a = "OH HAI"; say $a } }; foo'
Cannot assign to an immutable value
in any at -e:1
in block <unit> at -e:1

$ perl6-j -e 'macro foo { quasi { my $a = "OH HAI"; say $a } }; foo'
java.lang.NullPointerException
in any at -e:1
in block <unit> at -e:1

Nicholas Clark

unread,
Oct 21, 2014, 2:30:02 PM10/21/14
to Christian Bartolomaeus via RT, perl6-c...@perl.org
On Tue, Oct 14, 2014 at 04:45:47AM -0700, Christian Bartolomaeus via RT wrote:
> Just an update: Parrot no longer segfaults, but Moar does:
>
> $ perl6-m -e 'macro foo { quasi { my $a = "OH HAI"; say $a } }; foo'
> Segmentation fault

==23928== Invalid read of size 8
==23928== at 0x4F57A5E: MVM_interp_run (interp.c:1226)
==23928== by 0x502FBA3: MVM_vm_run_file (moar.c:208)
==23928== by 0x40110D: main (main.c:191)
==23928== Address 0x10 is not stack'd, malloc'd or (recently) free'd
==23928==
==23928==
==23928== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==23928== Access not within mapped region at address 0x10
==23928== at 0x4F57A5E: MVM_interp_run (interp.c:1226)
==23928== by 0x502FBA3: MVM_vm_run_file (moar.c:208)
==23928== by 0x40110D: main (main.c:191)

This is the same C backtrace as #120397, in OP(assign)

Nicholas Clark

Matthew Wilson via RT

unread,
Apr 7, 2016, 2:00:02 PM4/7/16
to perl6-c...@perl.org
new behavior:

13:48 <diakopter> m: use experimental :macros; macro foo { quasi { my $a = "OH HAI"; say $a } }; foo
13:48 <camelia> rakudo-moar 61d231: OUTPUT«===SORRY!===␤Optimizer: No lexical $a found␤»

0 new messages