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

Lexical subs aren't found during attribute initialization in Rakudo #1674

Closed
p6rt opened this issue Apr 9, 2010 · 9 comments
Closed

Lexical subs aren't found during attribute initialization in Rakudo #1674

p6rt opened this issue Apr 9, 2010 · 9 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 9, 2010

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

Searchable as RT74186$

@p6rt
Copy link
Author

p6rt commented Apr 9, 2010

From @masak

<masak> rakudo​: class A { sub b { 0x10 }; has $!c = b }; A.new
<p6eval> rakudo 4c94d7​: OUTPUT«Could not find sub &b [...]
<masak`> this is biting me currently. I use subs because constants
didn't work in classes in alpha, and don't work at all in master.
<masak> jnthn​: any ideas why this might be?
<jnthn> masak​: lexical scope f'up, I guess.
* masak submits rakudobug
<jnthn> masak​: file Rakudo bug but I can probably fix that without too
much trouble.
<masak> \o/
<jnthn> rakudo​: class A { our sub b { 0x10 }; has $!c = b }; A.new
<p6eval> rakudo 4c94d7​: ( no output )
<jnthn> masak​: Horrible workaround above.
<masak> good to know.

@p6rt
Copy link
Author

p6rt commented May 25, 2010

From @masak

<masak> rakudo​: class A { sub b { 0x10 }; has $!c = b }; A.new
<p6eval> rakudo 4c94d7​: OUTPUT«Could not find sub &b [...]
<masak`> this is biting me currently. I use subs because constants
didn't work in classes in alpha, and don't work at all in master.
<masak> jnthn​: any ideas why this might be?
<jnthn> masak​: lexical scope f'up, I guess.
* masak submits rakudobug
<jnthn> masak​: file Rakudo bug but I can probably fix that without too
much trouble.
<masak> \o/

Calling &b from the class scope in general works fine, but not in the
RHS of an assignment to an attribute declaration.

@p6rt
Copy link
Author

p6rt commented Jul 15, 2010

From @jnthn

On Fri Apr 09 09​:14​:07 2010, masak wrote​:

<masak> rakudo​: class A { sub b { 0x10 }; has $!c = b }; A.new
<p6eval> rakudo 4c94d7​: OUTPUT«Could not find sub &b [...]
<masak`> this is biting me currently. I use subs because constants
didn't work in classes in alpha, and don't work at all in master.
<masak> jnthn​: any ideas why this might be?
<jnthn> masak​: lexical scope f'up, I guess.
* masak submits rakudobug

Unf'up'd now.

class A { sub b { 0x10 }; has $!c = b; method c { say $!c } }; A.new.c
16

Given to moritz++ for spectesting.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Jul 15, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 16, 2010

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

@p6rt p6rt closed this as completed Jul 16, 2010
@p6rt
Copy link
Author

p6rt commented Jul 16, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S12-attributes/instance.t

commit 8a69002619251c8f4b03425e40a01e4b0483ee1a
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Fri Jul 16 07​:56​:35 2010 +0000

  [t/spec] tests for RT #​74186, unfudge two similar tests, and switch to planless testing
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31719 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-attributes/instance.t b/t/spec/S12-attributes/instance.t
index 27c6d9b..0f49b1f 100644
--- a/t/spec/S12-attributes/instance.t
+++ b/t/spec/S12-attributes/instance.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 129;
+plan *;
 
 =begin pod
 
@@ -26,7 +26,7 @@ class Foo1 { has $.bar; };
     }, '.. checking autogenerated accessor existence';
     ok($val, '... $foo.can("bar") should have returned true');
     ok($foo.bar().notdef, '.. autogenerated accessor works');
-    ok($foo.bar.notdef, '.. autogenerated accessor works w/out parens');    
+    ok($foo.bar.notdef, '.. autogenerated accessor works w/out parens');
 }
 
 # L<S12/Attributes/Pseudo-assignment to an attribute declaration specifies the default>
@@ -187,7 +187,6 @@ class Foo1 { has $.bar; };
 class Foo7e { has $.attr = 42 }
 is Foo7e.new.attr, 42, "default attribute value (1)";
 
-#?rakudo todo 'scoping issues'
 {
     my $was_in_supplier = 0;
     sub forty_two_supplier() { $was_in_supplier++; 42 }
@@ -576,4 +575,19 @@ is Foo7e.new.attr, 42, "default attribute value (1)";
 }
 
 
+# RT #74186
+{
+    sub outer { 42 };
+    class AttribLex {
+        sub inner { 23 };
+        has $.outer = outer();
+        has $.inner = inner();
+    }
+    is AttribLex.new.outer, 42, 'Can use outer lexicals in attribut initialization';
+    is AttribLex.new.inner, 23, 'Can use lexicals in attribut initialization';
+
+}
+
+done_testing();
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Aug 11, 2010

From @coke

On Tue May 25 06​:41​:53 2010, masak wrote​:

<masak> rakudo​: class A { sub b { 0x10 }; has $!c = b }; A.new
<p6eval> rakudo 4c94d7​: OUTPUT«Could not find sub &b [...]
<masak`> this is biting me currently. I use subs because constants
didn't work in classes in alpha, and don't work at all in master.
<masak> jnthn​: any ideas why this might be?
<jnthn> masak​: lexical scope f'up, I guess.
* masak submits rakudobug
<jnthn> masak​: file Rakudo bug but I can probably fix that without too
much trouble.
<masak> \o/

Calling &b from the class scope in general works fine, but not in the
RHS of an assignment to an attribute declaration.

This no longer dies; Does it do what you want, though?

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Aug 11, 2010

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

@p6rt
Copy link
Author

p6rt commented Aug 12, 2010

From @masak

masak (>>), coke (>)​:

<masak> rakudo​: class A { sub b { 0x10 }; has $!c = b }; A.new
<p6eval> rakudo 4c94d7​: OUTPUT«Could not find sub &b [...]
<masak`> this is biting me currently. I use subs because constants
didn't work in classes in alpha, and don't work at all in master.
<masak> jnthn​: any ideas why this might be?
<jnthn> masak​: lexical scope f'up, I guess.
* masak submits rakudobug
<jnthn> masak​: file Rakudo bug but I can probably fix that without too
much trouble.
<masak> \o/

Calling &b from the class scope in general works fine, but not in the
RHS of an assignment to an attribute declaration.

This no longer dies; Does it do what you want, though?

Seems it does.

<masak> rakudo​: class A { sub b { 0x10 }; has $!c = b; method foo { $!c } }; say A.new.foo
<p6eval> rakudo 69561e​: OUTPUT«16␤»
<masak> \o/

Taking to tests.

@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