Skip to content

Instantly share code, notes, and snippets.

@arnsholt
Created July 30, 2012 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnsholt/3206774 to your computer and use it in GitHub Desktop.
Save arnsholt/3206774 to your computer and use it in GitHub Desktop.
Patch
diff --git a/src/core/traits.pm b/src/core/traits.pm
index 885823d..8049b3b 100644
--- a/src/core/traits.pm
+++ b/src/core/traits.pm
@@ -15,6 +15,7 @@ my class X::Inheritance::Unsupported { ... }
my class X::Export::NameClash { ... }
my class X::Composition::NotComposable { ... }
my class X::Import::MissingSymbols { ... }
+my class X::Redeclaration { ... }
proto trait_mod:<is>(|$) { * }
multi trait_mod:<is>(Mu:U $child, Mu:U $parent) {
@@ -162,6 +163,10 @@ multi trait_mod:<of>(Mu:U $target, Mu:U $type) {
$target.HOW.set_of($target, $type);
}
multi trait_mod:<of>(Routine:D $target, Mu:U $type) {
+ my $returns := nqp::getattr(nqp::p6decont($target.signature), Signature, '$!returns');
+ X::Redeclaration.new(what => 'return type for', symbol => $target,
+ postfix => " (previous return type was {$returns.^name})").throw
+ if not nqp::isnull($returns);
$target.signature.set_returns($type)
}
@@ -174,6 +179,10 @@ multi trait_mod:<is>(Routine:D $r, :$hidden_from_backtrace!) {
proto trait_mod:<returns>(|$) { * }
multi trait_mod:<returns>(Routine:D $target, Mu:U $type) {
+ my $returns := nqp::getattr(nqp::p6decont($target.signature), Signature, '$!returns');
+ X::Redeclaration.new(what => 'return type for', symbol => $target,
+ postfix => " (previous return type was {$returns.^name})").throw
+ if not nqp::isnull($returns);
$target.signature.set_returns($type)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment