From adc9683773ffd3b4399fce122e8a70332d428baa Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Wed, 31 Oct 2018 13:11:02 +0100 Subject: [PATCH] Don't return standard .perl for classes with custom .new - also make code more idiomatic Perl 6 - return "Class.new(...)" for now with custom new - step 1 in fixing R#2448 --- src/core/Mu.pm6 | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/core/Mu.pm6 b/src/core/Mu.pm6 index 5203a99a70a..afaf4d2003f 100644 --- a/src/core/Mu.pm6 +++ b/src/core/Mu.pm6 @@ -634,20 +634,21 @@ Perhaps it can be found at https://docs.perl6.org/type/$name" proto method perl(|) {*} multi method perl(Mu:U:) { self.^name } multi method perl(Mu:D:) { - nqp::if( - nqp::eqaddr(self,IterationEnd), - "IterationEnd", - nqp::if( - nqp::iscont(self), # a Proxy object would have a conted `self` - nqp::decont(self).perl, - self.perlseen: self.^name, { - my @attrs; - for self.^attributes().flat.grep: { .has_accessor } -> $attr { - my $name := substr($attr.Str,2); - @attrs.push: $name ~ ' => ' ~ $attr.get_value(self).perl - } - self.^name ~ '.new' ~ ('(' ~ @attrs.join(', ') ~ ')' if @attrs) - })) + nqp::eqaddr(self,IterationEnd) + ?? "IterationEnd" + !! nqp::iscont(self) # Proxy object would have a conted `self` + ?? nqp::decont(self).perl + !! self.perlseen: self.^name, + nqp::eqaddr(self.^find_method("new"),Mu.^find_method("new")) + ?? { + my @attrs = self.^attributes + .grep( { .has_accessor } ) + .map: { "$_.Str.substr(2) => $_.get_value(self).perl()" } + @attrs + ?? self.^name ~ ".new(@attrs.join(', '))" + !! self.^name ~ ".new" + } + !! { self.^name ~ ".new(...)" } } proto method DUMP(|) {*}