From d067abf47aac34ab93464d1a14c288187437734c Mon Sep 17 00:00:00 2001 From: LLFourn Date: Thu, 6 Jul 2017 18:38:14 +1000 Subject: [PATCH] Fix 'is export' on constants assigned to routines The 'is export' exception catchall was higher precedence than the constant exporting candidate in the case of Routine. This patch makes `constant $sub is export = sub { ... }` take the same path as `sub foo is export { ... }` while preserving the constant variable's symbol. Fixes "Can't use unknown trait 'is export' in a ... declaration" for statements like: constant $constant-regex is export = /fo*/; constant &constant-sub is export = sub { "win" }; Zoffix++ for the patch --- src/core/traits.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/traits.pm b/src/core/traits.pm index 46b7cb18715..e6ff62515f5 100644 --- a/src/core/traits.pm +++ b/src/core/traits.pm @@ -251,13 +251,12 @@ my $!; my $/; my $_; -multi sub trait_mod:(Routine:D \r, :$export!) { +multi sub trait_mod:(Routine:D \r, :$export!, :$SYMBOL = '&' ~ r.name) { my $to_export := r.multi ?? r.dispatcher !! r; - my $exp_name := '&' ~ r.name; my @tags = flat 'ALL', (nqp::istype($export,Pair) ?? $export.key() !! nqp::istype($export,Positional) ?? @($export)>>.key !! 'DEFAULT'); - Rakudo::Internals.EXPORT_SYMBOL($exp_name, @tags, $to_export); + Rakudo::Internals.EXPORT_SYMBOL(nqp::decont($SYMBOL), @tags, $to_export); } multi sub trait_mod:(Mu:U \type, :$export!) { my $exp_name := type.^shortname;