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

Cannot delegate from user-defined .new to self.Object::new in Rakudo #1353

Closed
p6rt opened this issue Oct 9, 2009 · 5 comments
Closed

Cannot delegate from user-defined .new to self.Object::new in Rakudo #1353

p6rt opened this issue Oct 9, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 9, 2009

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

Searchable as RT69676$

@p6rt
Copy link
Author

p6rt commented Oct 9, 2009

From @masak

<masak> rakudo​: class A { has $.a; has $.b; method new($a, $b) {
self.new(​:$a, :$b) } }; say .a, .b for A.new(42, "OH HAI")
<p6eval> rakudo daf221​: OUTPUT«invalid arg type in named portion of args [...]
<masak> above, I tried to delegate to the Object​::new method
<masak> another attempt​:
<masak> rakudo​: class A { has $.a; has $.b; method new($a, $b) {
self.Object​::new(​:$a, :$b) } }; say .a, .b for A.new(42, "OH HAI")
<p6eval> rakudo daf221​: OUTPUT«elements() not implemented in class
'Sub'␤in method A​::new [...]
<masak> o.O
* masak submits rakudobug
<masak> both of those should work, no?
<moritz_> masak​: aye. There's a (known to me at least) problem with
the default new() method disappearing when an own such method is
defined
<masak> aye.
<masak> I knew that too. :)
<masak> but now I also know that it cannot be dug up either.
<moritz_> maybe moving Object.new to the setting migth help

@p6rt
Copy link
Author

p6rt commented Jul 15, 2010

From @jnthn

On Fri Oct 09 02​:14​:30 2009, masak wrote​:

<masak> rakudo​: class A { has $.a; has $.b; method new($a, $b) {
self.new(​:$a, :$b) } }; say .a, .b for A.new(42, "OH HAI")
<p6eval> rakudo daf221​: OUTPUT«invalid arg type in named portion of
args [...]
<masak> above, I tried to delegate to the Object​::new method

Fail. This is just a recursive call to the same method. However, Rakudo
failed it in the wrong way before; it's right now.

class A { has $.a; has $.b; method new($a, $b) { self.new(​:$a, :$b) }
}; say .a, .b for A.new(42, "OH HAI")
maximum recursion depth exceeded

<masak> another attempt​:
<masak> rakudo​: class A { has $.a; has $.b; method new($a, $b) {
self.Object​::new(​:$a, :$b) } }; say .a, .b for A.new(42, "OH HAI")
<p6eval> rakudo daf221​: OUTPUT«elements() not implemented in class
'Sub'␤in method A​::new [...]
<masak> o.O
* masak submits rakudobug

And after some s/Object/Mu/, this now works​:

class A { has $.a; has $.b; method new($a, $b) { self.Mu​::new(​:$a,
:$b) } }; say .a, .b for A.new(42, "OH HAI")
42OH HAI

Giving 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 18, 2010

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

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

p6rt commented Jul 18, 2010

From @kyleha

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

commit bab5843563abbdd1932d8f6436b16d74009ce39a
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sun Jul 18 12​:04​:09 2010 +0000

  [t/spec] tests for RT #​69676, delegating .new to self.Mu​::new
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31745 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-construction/new.t b/t/spec/S12-construction/new.t
index c9ae68e..38894c9 100644
--- a/t/spec/S12-construction/new.t
+++ b/t/spec/S12-construction/new.t
@@ -56,6 +56,23 @@ is $o.x, 5, '... worked for the class Parent (other order)';
     dies_ok { RT71706::Artie.new }, 'die trying to instantiate missing class';
 }
 
+# RT #69676
+{
+    class NewFromMu {
+        has $.x;
+        has $.y;
+
+        method new($a, $b) {
+            self.Mu::new(:x($a), :y($b));
+        }
+    }
+
+    my $x;
+    lives_ok { $x = NewFromMu.new('j', 'k') }, 'can delegate to self.Mu::new';
+    is $x.x, 'j', '... got the right attribute (1)';
+    is $x.y, 'k', '... got the right attribute (2)';
+}
+
 done_testing;
 
 # vim: ft=perl6

@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