Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Catch variable use before declaration (RT #61838)
Does not catch unused non-$ variables in double quoted strings.

This also moves $Inf and $NaN to an earlier setting file, because
they were used before the declaration.

It also contains a very ugly workaound around a problem with the nqp
%markhash being global, and reused for multiple evals. This bug
was exposed by other parts of the patch.
  • Loading branch information
moritz committed Nov 2, 2011
1 parent 430c564 commit d307831
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -1053,6 +1053,18 @@ class Perl6::Actions is HLL::Actions {
$past.unshift(PAST::Var.new( :name('self'), :scope('lexical_6model') ));
}
elsif $*IN_DECL ne 'variable' {
# the $*QSGIL part is a hack:
# when we parse double-quoted strings like "@a", the @a is
# first parsed as a variable, and thus checked. So it throws
# an exception even if turns out not to end in a postcircumfix
#
# I don't know what the correct solution is. Disabling the check
# inside double quotes fixes the most common case, but fails to
# catch undeclared variables in double-quoted strings.
if $sigil ne '&' && !$*IN_DECL && ($*QSIGIL eq '' || $*QSIGIL eq '$') && !$*ST.is_lexical($name) {
$/.CURSOR.panic("Variable $name is not predeclared");
}

# Expect variable to have been declared somewhere.
# Locate descriptor and thus type.
try {
Expand Down
5 changes: 4 additions & 1 deletion src/Perl6/Grammar.pm
Expand Up @@ -28,7 +28,10 @@ grammar Perl6::Grammar is HLL::Grammar {
my $*ST := pir::isnull($file) ??
Perl6::SymbolTable.new(:handle(~pir::time__N())) !!
Perl6::SymbolTable.new(:handle(~pir::time__N()), :description($file));


# XXX Hack: clear any marks.
pir::set_hll_global__vPsP(['HLL', 'Grammar'], '%!MARKHASH', nqp::null());

self.comp_unit;
}

Expand Down
6 changes: 0 additions & 6 deletions src/core/Num.pm
@@ -1,10 +1,4 @@

# XXX: Temporary definition of $Inf and $NaN until we have constants available
# constant Inf = ...
# constant NaN = ...
my $Inf = nqp::p6box_n(pir::set__Ns('Inf'));
my $NaN = nqp::p6box_n(pir::set__Ns('NaN'));

my class Num {
method Num() { self }
method Bridge(Num:D:) { self }
Expand Down
8 changes: 8 additions & 0 deletions src/core/control.pm
Expand Up @@ -177,6 +177,14 @@ sub shell($cmd) {
$status;
}

# XXX: Temporary definition of $Inf and $NaN until we have constants ava
# need to come pretty early, because we use it in lots of setting files
# constant Inf = ...
# constant NaN = ...
my $Inf = nqp::p6box_n(pir::set__Ns('Inf'));
my $NaN = nqp::p6box_n(pir::set__Ns('NaN'));


sub sleep($seconds = $Inf) { # fractional seconds also allowed
my $time1 = time;
if $seconds ~~ $Inf {
Expand Down

0 comments on commit d307831

Please sign in to comment.