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

Putting a 'use' statement inside a method causes Rakudo to emit a confused error about not being in a class #1639

Closed
p6rt opened this issue Mar 29, 2010 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 29, 2010

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

Searchable as RT73886$

@p6rt
Copy link
Author

p6rt commented Mar 29, 2010

From @masak

$ cat A.pm
grammar A {
}

$ cat B.pm
class B;

method foo() {
  use A;
}

$ perl6 B.pm
You can not add a Method to a module; use a class, role or grammar
[...]

I'm assuming that the above should work. (It does in alpha, and in Perl 5.)

@p6rt
Copy link
Author

p6rt commented Apr 4, 2010

From @jnthn

On Mon Mar 29 08​:41​:18 2010, masak wrote​:

$ cat A.pm
grammar A {
}

$ cat B.pm
class B;

method foo() {
use A;
}

$ perl6 B.pm
You can not add a Method to a module; use a class, role or grammar
[...]

I'm assuming that the above should work. (It does in alpha, and in
Perl 5.)

Fixed; given to moritz++ for spectests.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Apr 4, 2010

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

@p6rt
Copy link
Author

p6rt commented Apr 30, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S10-packages/use-with-class.t

commit d8944e8b6eac93f4cace32bbc6588b0d323b0320
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Fri Apr 30 19​:33​:41 2010 +0000

  [t/spec] Test for RT #​73886, loading a class from inside a method
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;30527 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S10-packages/use-with-class.t b/t/spec/S10-packages/use-with-class.t
index e2b7801..ec664bf 100644
--- a/t/spec/S10-packages/use-with-class.t
+++ b/t/spec/S10-packages/use-with-class.t
@@ -5,7 +5,7 @@ use Test;
 
 # L<S11/Compile-time Importation>
 
-plan 7;
+plan 8;
 
 # test that 'use' imports class names defined in importet packages
 
@@ -32,4 +32,18 @@ eval_lives_ok 'Stupid::Class.new()', 'can instantiate object of "imported" class
 
 }
 
+# class loading inside a method
+# RT #73886
+{
+    BEGIN { @*INC.push: 't/spec/packages' }
+    class MethodLoadingTest {
+        method doit {
+            use Foo;
+            Foo.new.foo();
+        }
+    }
+    is MethodLoadingTest.doit(), 'foo', 'can load class from inside a method';
+
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Apr 30, 2010

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

@p6rt p6rt closed this as completed Apr 30, 2010
@p6rt p6rt added the Bug 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