Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Variables declared in quasi blocks don't work in Rakudo #2954

Open p6rt opened 12 years ago

p6rt commented 12 years ago

Migrated from rt.perl.org#115566 (status was 'stalled')

Searchable as RT115566$

p6rt commented 12 years ago

From @masak

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

p6rt commented 10 years ago

From @masak

\ r​: macro quux { quasi { my $foo = ""; $foo; }; }; constant bar = quux; \ rakudo-jvm 53c60c​: OUTPUT«(timeout)» \ ..rakudo-parrot 53c60c​: OUTPUT«(signal SEGV)» * masak submits rakudobug \ r​: macro x { quasi { my $foo = ""; $foo } }; constant y = x; say "alive" \ rakudo-jvm 53c60c​: OUTPUT«(timeout)» \ ..rakudo-parrot 53c60c​: OUTPUT«(signal SEGV)» \ oh, this one is already reported... \ huh, apparently not separately reported. \ r​: macro x { quasi { my $foo = "" } }; x; say "alive" \ rakudo-parrot 53c60c​: OUTPUT«(signal SEGV)» \ ..rakudo-jvm 53c60c​: OUTPUT«java.lang.NullPointerException␤␤» \ no, there it is.

p6rt commented 10 years ago

From @usev6

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 \ 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 \ at -e​:1

p6rt commented 10 years ago

From @usev6

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 \ 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 \ at -e​:1

p6rt commented 10 years ago

@usev6 - Status changed from 'new' to 'open'

p6rt commented 10 years ago

From @nwc10

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

p6rt commented 8 years ago

From @diakopter

new behavior​:

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

p6rt commented 8 years ago

@coke - Status changed from 'open' to 'stalled'