Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable in EVAL'ed subregex doesn't get a proper lexical lookup #2634

Closed
p6rt opened this issue Mar 1, 2012 · 6 comments
Closed

Variable in EVAL'ed subregex doesn't get a proper lexical lookup #2634

p6rt opened this issue Mar 1, 2012 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Mar 1, 2012

Migrated from rt.perl.org#111474 (status was 'resolved')

Searchable as RT111474$

@p6rt
Copy link
Author

p6rt commented Mar 1, 2012

From @masak

<masak> nom​: https://gist.github.com/1951347
<p6eval> nom 48af8c​: OUTPUT«===SORRY!===␤Variable $a is not
declared␤at eval_0​:1␤»
<masak> huh!
<jnthn> nom​: "x" ~~ /​:my $a = 42; { say $a } <?>/
<p6eval> nom 48af8c​: OUTPUT«42␤»
<jnthn> oh...
<jnthn> it's eval'ing that regex, no?
<jnthn> masak​: if you can golf that one it'd be nice...
<masak> gotcha.
<masak> I'll golf it and then RT it.
<masak> nom​: '' ~~ / :my $a; <{ '$a' }> /
<p6eval> nom 48af8c​: OUTPUT«===SORRY!===␤Variable $a is not
declared␤at eval_0​:1␤»
<masak> golf'd.
* masak submits rakudobug

@p6rt
Copy link
Author

p6rt commented Mar 3, 2013

From @FROGGS

There are weird things goind on​:

good​:
<FROGGS> r​: '' ~~ / :my $a; <{ '$a' }> /
<p6eval> rakudo 123dfa​: ( no output )

good​:
<FROGGS> r​: say '' ~~ / :my $a; <{ '$a' }> /
<p6eval> rakudo 123dfa​: OUTPUT«#<failed match>␤»

weird​:
<FROGGS> r​: say '123' ~~ / :my $a=2; <{ '$a' }> /
<p6eval> rakudo 123dfa​: OUTPUT«「1」␤␤»

good​:
<FROGGS> r​: say '123' ~~ / :my $a=2; <{ "$a" }> /
<p6eval> rakudo 123dfa​: OUTPUT«「2」␤␤»

weird​:
<FROGGS> r​: say '$a' ~~ / :my $a=2; <{ '$a' }> /
<p6eval> rakudo 123dfa​: OUTPUT«#<failed match>␤»

good​:
<FROGGS> std​: say '$a' ~~ / <{ '$a' }> /
<p6eval> std 52fe6d2​: OUTPUT«ok 00​:00 43m␤»

IMO only variables in double quotes should interpolate. so '$a' should
be treatet as that string.

@p6rt
Copy link
Author

p6rt commented Mar 3, 2013

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

On Thu, 01 Mar 2012 13​:07​:28 -0800, masak wrote​:

<masak> nom​: '' ~~ / :my $a; <{ '$a' }> /
<p6eval> nom 48af8c​: OUTPUT«===SORRY!===␤Variable $a is not
declared␤at eval_0​:1␤»

This works fine now - and has so for a while¹, apparently since a commit² in May 2015​:

  say '123' ~~ / :my $a=2; <{ '$a' }> /, # '2'


[1] https://gist.github.com/Whateverable/1df76358c7486886538f9ead60b13d1f
[2] rakudo/rakudo@f0e142b

@p6rt
Copy link
Author

p6rt commented Sep 17, 2017

From @skids

On Sun, 03 Mar 2013 10​:47​:32 -0800, FROGGS.de wrote​:

There are weird things goind on​:

good​:
<FROGGS> r​: '' ~~ / :my $a; <{ '$a' }> /
<p6eval> rakudo 123dfa​: ( no output )

good​:
<FROGGS> r​: say '' ~~ / :my $a; <{ '$a' }> /
<p6eval> rakudo 123dfa​: OUTPUT«#<failed match>␤»

weird​:
<FROGGS> r​: say '123' ~~ / :my $a=2; <{ '$a' }> /
<p6eval> rakudo 123dfa​: OUTPUT«「1」␤␤»

good​:
<FROGGS> r​: say '123' ~~ / :my $a=2; <{ "$a" }> /
<p6eval> rakudo 123dfa​: OUTPUT«「2」␤␤»

weird​:
<FROGGS> r​: say '$a' ~~ / :my $a=2; <{ '$a' }> /
<p6eval> rakudo 123dfa​: OUTPUT«#<failed match>␤»

good​:
<FROGGS> std​: say '$a' ~~ / <{ '$a' }> /
<p6eval> std 52fe6d2​: OUTPUT«ok 00​:00 43m␤»

IMO only variables in double quotes should interpolate. so '$a' should
be treatet as that string.

As per the other reply, first { '$a' } produces the string $a,
then that string is interpreted as a regex which contains a
variable lookup, and the lexical lookup for $a is expected too work,
so the second "weird" example is functioning as intended.

Tests, including making sure $a is not expanded before the
closure returns, were added in roast commit 1bbe3c9d3, so resolving this ticket.

@p6rt p6rt closed this as completed Sep 17, 2017
@p6rt
Copy link
Author

p6rt commented Sep 17, 2017

@skids - Status changed from 'open' to 'resolved'

@p6rt p6rt added the testneeded label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant