Skip to content

Commit f4a923d

Browse files
committed
Fix GLOBAL::foo and contextual fallback. Fixes regressions in package var test script, apart from one that is dubious.
1 parent 628e050 commit f4a923d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/NQP/Actions.pm

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,14 @@ class NQP::Actions is HLL::Actions {
425425
$past.viviself( vivitype( $<sigil> ) );
426426
}
427427
elsif $<twigil>[0] eq '*' {
428+
my $global_fallback := lexical_package_lookup(['GLOBAL', ~$<sigil> ~ $<desigilname>], $/);
429+
$global_fallback.viviself(PAST::Op.new(
430+
'Contextual ' ~ ~$/ ~ ' not found',
431+
:pirop('die')
432+
));
428433
$past := PAST::Var.new(
429434
:name(~@name.pop), :scope('contextual'),
430-
:viviself(
431-
PAST::Var.new(
432-
:scope('package'), :namespace(''),
433-
:name( ~$<sigil> ~ $<desigilname> ),
434-
:viviself(
435-
PAST::Op.new( 'Contextual ' ~ ~$/ ~ ' not found',
436-
:pirop('die') )
437-
)
438-
)
439-
)
435+
:viviself($global_fallback)
440436
);
441437
}
442438
elsif $<twigil>[0] eq '!' {
@@ -1398,11 +1394,15 @@ class NQP::Actions is HLL::Actions {
13981394
}
13991395

14001396
# Otherwise, see if the first part of the name is lexically
1401-
# known. If not, it's in GLOBAL.
1397+
# known. If not, it's in GLOBAL. Also, if first part is GLOBAL
1398+
# then strip it off.
14021399
else {
14031400
my $path := is_lexical(@name[0]) ??
14041401
PAST::Var.new( :name(@name.shift()), :scope('lexical') ) !!
14051402
PAST::Var.new( :name('GLOBAL'), :namespace([]), :scope('package') );
1403+
if @name[0] eq 'GLOBAL' {
1404+
@name.shift();
1405+
}
14061406
for @name {
14071407
$path := PAST::Op.new(
14081408
:pirop('nqp_get_package_through_who PPs'),

0 commit comments

Comments
 (0)