@@ -414,7 +414,6 @@ method package_def($/) {
414
414
415
415
# Get the body code.
416
416
my $ past := $ < block > ?? $ < block > . ast !! $ < comp_unit > . ast;
417
- $ past . namespace( $ < name >< identifier > );
418
417
419
418
# Prefix the class initialization with initial setup. Also install it
420
419
# in the symbol table right away.
@@ -423,15 +422,23 @@ method package_def($/) {
423
422
PAST::Var. new ( : name(' type_obj' ), : scope(' register' ), : isdecl(1 ) ),
424
423
$ * SC . get_slot_past_for_object($ * PKGMETA )
425
424
),
426
- PAST::Op. new ( : pasttype(' bind' ),
427
- PAST::Var. new ( : name($ name ), : namespace(@ ns ), : scope(' package' ) ),
428
- PAST::Var. new ( : name(' type_obj' ), : scope(' register' ) )
429
- ),
430
425
PAST::Op. new ( : pasttype(' bind' ),
431
426
PAST::Var. new ( : name(' $?CLASS' ) ),
432
427
PAST::Var. new ( : name(' type_obj' ), : scope(' register' ) )
433
428
)
434
429
));
430
+
431
+ # Install it in the package or lexpad as needed.
432
+ if $ * SCOPE eq ' our' || $ * SCOPE eq ' ' {
433
+ $ past . namespace( $ < name >< identifier > );
434
+ $ * PACKAGE-SETUP [0 ]. push (PAST::Op. new ( : pasttype(' bind' ),
435
+ PAST::Var. new ( : name($ name ), : namespace(@ ns ), : scope(' package' ) ),
436
+ PAST::Var. new ( : name(' type_obj' ), : scope(' register' ) )
437
+ ));
438
+ }
439
+ else {
440
+ $/ . CURSOR. panic(" $ * SCOPE scoped packages are not supported" );
441
+ }
435
442
436
443
# Evaluate everything in the package in-line unless this is a generic
437
444
# type in which case it needs delayed evaluation. Normally, $?CLASS is
@@ -531,9 +538,9 @@ method scope_declarator:sym<our>($/) { make $<scoped>.ast; }
531
538
method scope_declarator :sym <has >($/ ) { make $ < scoped > . ast; }
532
539
533
540
method scoped ($/ ) {
534
- make $ < declarator >
535
- ?? $ < declarator > . ast
536
- !! $ < multi_declarator > . ast;
541
+ make $ < declarator > ?? $ < declarator > . ast !!
542
+ $ < multi_declarator > ?? $ < multi_declarator > . ast !!
543
+ $ < package_declarator > . ast;
537
544
}
538
545
539
546
method declarator ($/ ) {
0 commit comments