Skip to content

Commit

Permalink
RakuAST: disambiguate global lookup vs type capture in "is" traits
Browse files Browse the repository at this point in the history
In class Bar is ::Foo { } we parsed ::Foo as a type capture leading to a
confusing error message. Instead it should be parsed as a global lookup
(i.e. short for GLOBAL::Foo) which just looks the same.
  • Loading branch information
niner committed Apr 4, 2024
1 parent e64145d commit a4b6c40
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Raku/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3929,7 +3929,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
proto rule trait_mod {*}
rule trait_mod:sym<is> {
<.traitmod-is> [ <typename> || <longname><circumfix>? || <.panic: 'Invalid name'> ]
<.traitmod-is> [ <typename(:allow-capture(0))> || <longname><circumfix>? || <.panic: 'Invalid name'> ]
{
if $<circumfix> && nqp::eqat(self.orig, '{', $<longname>.to) {
$*BORG<block> := $<circumfix>;
Expand Down Expand Up @@ -4431,7 +4431,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
#-------------------------------------------------------------------------------
# Types
token typename {
token typename(:$allow-capture = 1) {
[
# parse ::?CLASS as special case
| '::?'<identifier> <colonpair>*
Expand All @@ -4441,7 +4441,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
<?{
# ::T introduces a type, so always is one
nqp::eqat(~$<longname>, '::', 0)
|| $*R.is-name-known($<longname>.ast.without-colonpairs)
?? $allow-capture
!! $*R.is-name-known($<longname>.ast.without-colonpairs)
}>
]
# parametric/coercion type?
Expand Down

0 comments on commit a4b6c40

Please sign in to comment.