Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'does' fails with roles that have '::' in their names #390

Closed
p6rt opened this issue Nov 6, 2008 · 5 comments
Closed

'does' fails with roles that have '::' in their names #390

p6rt opened this issue Nov 6, 2008 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 6, 2008

Migrated from rt.perl.org#60366 (status was 'resolved')

Searchable as RT60366$

@p6rt
Copy link
Author

p6rt commented Nov 6, 2008

From @chrisdolan

There are two bugs here. The attached patch fixes bug #​2 but not bug
#​1.

Bug #​1) "role A​::B" is not interpreted as a role, but just as a module.

  ./perl6 -e 'role A { method foo { say "Foo"; } }; say A.WHAT'
  Role

  ./perl6 -e 'role A​::B { method foo { say "Foo"; } }; say A​::B.WHAT'
  Module

Bug #​2) applying a role searches for the role in the wrong namespace.

  ./perl6 -e 'role A { method foo { say "Foo"; } }; class B does A
{}; B.new.foo'
  Foo

  ./perl6 -e 'role A { method foo { say "Foo"; } }; class A​::B​::C
does A {}; A​::B​::C.new.foo'
  Foo

  ./perl6 -e 'role A​::B { method foo { say "Foo"; } }; class B does
A​::B {}; B.new.foo'
  Method 'foo' not found for invocant of class 'B'

  ./perl6 -e 'role A​::B { method foo { say "Foo"; } }; class A​::B​::C
does A​::B {}; A​::B​::C.new.foo'
  Method 'foo' not found for invocant of class 'A;B;C'

With the patch, I instead get​:

  ./perl6 -e 'role A​::B { method foo { say "Foo"; } }; class B does
A​::B {}; B.new.foo'
  does keyword can only be used with roles.

which suggests that if the module/role bug were fixed, this code
would work.

@p6rt
Copy link
Author

p6rt commented Nov 6, 2008

From @chrisdolan

role.patch
Index: languages/perl6/src/parser/actions.pm
===================================================================
--- languages/perl6/src/parser/actions.pm	(revision 32369)
+++ languages/perl6/src/parser/actions.pm	(working copy)
@@ -1471,6 +1477,15 @@
         }
         elsif $aux<sym> eq 'does' {
             # Role.
+            my @identifier := Perl6::Compiler.parse_name(~$aux<name>);
+            my $name := @identifier.pop();
+            my $superrole := PAST::Var.new(
+                                 :name($name),
+                                 :scope('package'),
+                             );
+            if +@identifier != 0 {
+                $superrole.namespace(@identifier);
+            }
             $package.push(
                 PAST::Op.new(
                     :pasttype('call'),
@@ -1479,10 +1494,7 @@
                         :name('$def'),
                         :scope('lexical')
                     ),
-                    PAST::Var.new(
-                        :name(~$aux<name>),
-                        :scope('package')
-                    )
+                    $superrole
                 )
             );
         }

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

From @jnthn

On Wed Nov 05 22​:58​:18 2008, chris@​chrisdolan.net wrote​:

There are two bugs here. The attached patch fixes bug #​2 but not bug
#​1.

Bug #​1) "role A​::B" is not interpreted as a role, but just as a module.

./perl6 -e 'role A { method foo { say "Foo"; } }; say A.WHAT'
Role

./perl6 -e 'role A​::B { method foo { say "Foo"; } }; say A​::B.WHAT'
Module

Fixed.

Bug #​2) applying a role searches for the role in the wrong namespace.

./perl6 -e 'role A​::B { method foo { say "Foo"; } }; class B does
A​::B {}; B.new.foo'
Method 'foo' not found for invocant of class 'B'

./perl6 -e 'role A​::B { method foo { say "Foo"; } }; class A​::B​::C
does A​::B {}; A​::B​::C.new.foo'
Method 'foo' not found for invocant of class 'A;B;C'

Applied your patch with minor simplifications to the code and with my
fix to issue #​1, it does indeed resolve this issue.

Both in together as r33215, plus added a few tests.

Thanks!

Jonathan

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Nov 26, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant