Skip Menu |

From: Jonathan Scott Duff <duff [...] pobox.com>
Subject: Questionable "Variable not declared" error
Date: Tue, 6 May 2014 14:42:02 -0500
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 1.4k
19:30 <PerlJam> m: my %h is default(%h<foo>);  # surely this is a bug?
19:30 <+camelia> rakudo-moar 1ccc4d: OUTPUT«===SORRY!=== Error while compiling /tmp/HtntR_h3tN␤Variable '%h' is not 
                 declared␤at /tmp/HtntR_h3tN:1␤------> my %h is default(%h<foo>⏏);  # surely this is a bug?␤    
                 expecting any of:␤        postfix␤»
19:31 <masak> PerlJam: yes. it's a bug by the parsing principles of Perl 6, I would say.
19:31 <masak> PerlJam: as in, %h should be defined by that point.
19:31 <masak> s/defined/declared/
19:32 <masak> that's why something like this works:
19:32 <masak> m: my %h = %h; say %h
19:32 <+camelia> rakudo-moar 1ccc4d: OUTPUT«().hash␤»
19:33 -!- lizmat [~textual@ip-213-127-250-146.ip.prioritytelecom.net] has joined #perl6
19:34 <lizmat> PerlJam: could you rakudobug that?
19:34 <retupmoca> oh, that's interesting
19:34 <retupmoca> m: my $x = $x.^name; say $x; say $x.^name;
19:34 <+camelia> rakudo-moar 1ccc4d: OUTPUT«Any␤Str␤»
19:35 <jnthn> PerlJam, lizmat: I think it's 'cus the traits are part of the declaration...
19:36 <jnthn> And until we know there's no "is FooType" trait there, we don't actually know what container to install.
19:36 -!- lvfjf [~chatzilla@gateway/tor-sasl/lvfjf] has joined #perl6
19:36 <jnthn> So it's kinda a can of worms to open.
19:36 <lizmat> ok...  one of those things then...
19:36 <jnthn> "of" is similar
19:36 <PerlJam> sure, but the name %h is already in existence, so "Variable not declared" is LTA
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 400b
Since rakudo commit 3754356d8e this fails with X::Syntax::Variable::Initializer: $ perl6 -e 'my %h = %h; say %h' ===SORRY!=== Error while compiling -e Cannot use variable %h in declaration to initialize itself at -e:1 ------> my %h = %⏏h; say %h expecting any of: term I added a test with commit https://github.com/perl6/roast/commit/a254a271ba I'm closing this ticket as 'resolved'.
Alright, I'm reopening this.

The error message is indeed LTA, it should clearly indicate that the value needs to be known *at compile time*, and perhaps it can somehow explain why %h is not known to be declared at that point.

The new error message doesn't really resolve the issue. In fact, it is arguably even more confusing.

However, the whole idea of using %h<foo> as the default value is not going to work any time soon. It has to be a fixed value that should be known at compile-time. It's not just that %h<foo> doesn't work, anything else is not going to work also (e.g. %someotherhash<foo>).

Well, unless you do something like 「BEGIN my %z; BEGIN %z<foo> = 42」, which is clearly not what was required.


As I'm committing to revert the results of RT #125371 (which I wholeheartedly believe was a wrong move), the original behavior of 「is default(…)」 will be restored.

On 2015-10-28 14:46:32, bartolin@gmx.de wrote:
Show quoted text
> Since rakudo commit 3754356d8e this fails with
> X::Syntax::Variable::Initializer:
>
> $ perl6 -e 'my %h = %h; say %h'
> ===SORRY!=== Error while compiling -e
> Cannot use variable %h in declaration to initialize itself
> at -e:1
> ------> my %h = %⏏h; say %h
> expecting any of:
> term
>
> I added a test with commit
> https://github.com/perl6/roast/commit/a254a271ba
>
> I'm closing this ticket as 'resolved'.




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org