Skip to content
Permalink
Browse files

Don't bother with .? dispatch inside try blocks

Since apparently don't care about the result if we can't get it, we don't
need to be careful about calling a potentially non-existing method.
  • Loading branch information...
lizmat committed May 28, 2019
1 parent ffc47aa commit 2b0ac401af75544b3db711b70ef996f17cc483db
Showing with 8 additions and 8 deletions.
  1. +5 −5 src/core/Exception.pm6
  2. +1 −1 src/core/Failure.pm6
  3. +2 −2 src/core/Mu.pm6
@@ -28,7 +28,7 @@ my class Exception {
my str $message = nqp::getmessage($!ex);
$str = nqp::isnull_s($message) ?? '' !! nqp::p6box_s($message);
}
$str ||= (try self.?message);
$str ||= (try self.message);
$str = ~$str if defined $str;
$str // "Something went wrong in {self.WHAT.gist}";
}
@@ -38,15 +38,15 @@ my class Exception {
if nqp::isconcrete($!ex) {
my str $message = nqp::getmessage($!ex);
$str = nqp::isnull_s($message)
?? (try self.?message) // "Died with {self.^name}"
?? (try self.message) // "Died with {self.^name}"
!! nqp::p6box_s($message);
$str ~= "\n";
try $str ~= self.backtrace
|| Backtrace.new()
|| ' (no backtrace available)';
}
else {
$str = (try self.?message) // "Unthrown {self.^name} with no message";
$str = (try self.message) // "Unthrown {self.^name} with no message";
}
$str;
}
@@ -2632,7 +2632,7 @@ my class X::Multi::Ambiguous is Exception {
@bits.push(':' ~ ('!' x !.value) ~ .key);
}
else {
try @bits.push(":$(.key)\($(.value.WHAT.?perl))");
try @bits.push(":$(.key)\($(.value.WHAT.perl))");
@bits.push(':' ~ .value.^name) if $!;
}
}
@@ -2692,7 +2692,7 @@ my class X::Multi::NoMatch is Exception {
else {
try @bits.push(":$(.key)\($($where
?? Rakudo::Internals.SHORT-GIST: .value
!! .value.WHAT.?perl
!! .value.WHAT.perl
))");
@bits.push(':' ~ .value.^name) if $!;
}
@@ -96,7 +96,7 @@ my class Failure is Nil {
}
multi method perl(Failure:U:) { self.^name }
method mess (Failure:D:) {
my $message = (try self.exception.?message) // self.exception.^name ~ ' with no message';
my $message = (try self.exception.message) // self.exception.^name ~ ' with no message';
"(HANDLED) " x $!handled ~ "$message\n" ~ self.backtrace;
}

@@ -545,7 +545,7 @@ Perhaps it can be found at https://docs.perl6.org/type/$name"

proto method Str(|) {*}
multi method Str(Mu:U \v:) {
my $name = (defined($*VAR_NAME) ?? $*VAR_NAME !! try v.VAR.?name) // '';
my $name = (defined($*VAR_NAME) ?? $*VAR_NAME !! try v.VAR.name) // '';
$name ~= ' ' if $name ne '';
warn "Use of uninitialized value {$name}of type {self.^name} in string"
~ " context.\nMethods .^name, .perl, .gist, or .say can be"
@@ -562,7 +562,7 @@ Perhaps it can be found at https://docs.perl6.org/type/$name"

proto method Stringy(|) {*}
multi method Stringy(Mu:U \v:) {
my $*VAR_NAME = try v.VAR.?name;
my $*VAR_NAME = try v.VAR.name;
self.Str
}
multi method Stringy(Mu:D $:) { self.Str }

0 comments on commit 2b0ac40

Please sign in to comment.
You can’t perform that action at this time.