Skip to content

Commit

Permalink
warn about clashing enum aliases, and also poison these aliases
Browse files Browse the repository at this point in the history
This resolves RT #72696.
  • Loading branch information
FROGGS committed Nov 9, 2014
1 parent acea0c1 commit e340863
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog
@@ -1,6 +1,7 @@
New in 2014.11
+ method 'for' as an alias for 'map'. Map will stop flattening the list eventually, 'for' remains as it is now.
+ method 'unique' as a successor for 'uniq'
+ warn about clashing enum aliases, and also poison these aliases

New in 2014.10
+ unstrict mode now default with -e
Expand Down
34 changes: 31 additions & 3 deletions src/Perl6/Actions.nqp
Expand Up @@ -3313,6 +3313,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
# XXX Should not assume integers, and should use lexically
# scoped &postfix:<++> or so.
my $cur_value := nqp::box_i(-1, $*W.find_symbol(['Int']));
my @redecl;
for @values {
# If it's a pair, take that as the value; also find
# key.
Expand Down Expand Up @@ -3358,14 +3359,41 @@ class Perl6::Actions is HLL::Actions does STDActions {

# Create and install value.
my $val_obj := $*W.create_enum_value($type_obj, $cur_key, $cur_value);
$*W.install_package_symbol($type_obj, nqp::unbox_s($cur_key), $val_obj);
$cur_key := nqp::unbox_s($cur_key);
$*W.install_package_symbol($type_obj, $cur_key, $val_obj);
if $*SCOPE ne 'anon' {
$*W.install_lexical_symbol($*W.cur_lexpad(), nqp::unbox_s($cur_key), $val_obj);
if $*W.is_lexical($cur_key) {
nqp::push(@redecl, $cur_key);
$*W.install_lexical_symbol($*W.cur_lexpad(), $cur_key,
$*W.find_symbol(['Failure']).new(
$*W.find_symbol(['X', 'PoisonedAlias']).new(
:alias($cur_key), :package-type<enum>, :package-name($name)
)
)
);
}
else {
$*W.install_lexical_symbol($*W.cur_lexpad(), $cur_key, $val_obj);
}
}
if $*SCOPE eq '' || $*SCOPE eq 'our' {
$*W.install_package_symbol($*PACKAGE, nqp::unbox_s($cur_key), $val_obj);
$*W.install_package_symbol($*PACKAGE, $cur_key, $val_obj);
}
}

if +@redecl -> $amount {
if $amount > 2 {
@redecl[$amount - 2] := @redecl[$amount - 2] ~ ' and ' ~ nqp::pop(@redecl);
$/.CURSOR.typed_worry('X::Redeclaration', symbol => nqp::join(', ', @redecl));
}
elsif $amount > 1 {
$/.CURSOR.typed_worry('X::Redeclaration', symbol => nqp::join(' and ', @redecl));
}
else {
$/.CURSOR.typed_worry('X::Redeclaration', symbol => @redecl[0]);
}
}

# create a type object even for empty enums
make_type_obj($*W.find_symbol(['Int'])) unless $has_base_type;

Expand Down
10 changes: 10 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -705,6 +705,16 @@ my class X::Import::OnlystarProto does X::Comp {
}
}

my class X::PoisonedAlias does X::Comp {
has $.alias;
has $.package-type = 'package';
has $.package-name;
method message() {
"Cannot use poisoned alias $!alias, because it was declared by several {$!package-type}s." ~
($!package-name ?? "\nPlease access it via explicit package name like: {$!package-name}::{$!alias}" !! '')
}
}

my class X::Phaser::Multiple does X::Comp {
has $.block;
method message() { "Only one $.block block is allowed" }
Expand Down

0 comments on commit e340863

Please sign in to comment.