Permalink
Browse files

Make :delete give a better error message if not supported on the object

  • Loading branch information...
1 parent 9f94b8c commit 11bada4fe1f60456e59e502d2d36de0749799d46 @lizmat lizmat committed Oct 5, 2013
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/core/Any.pm
View
@@ -21,8 +21,18 @@ my class Any { # declared in BOOTSTRAP
once DEPRECATED("Method 'Any.delete'", "the :delete adverb");
Nil;
}
- method delete_key(Any:U: $key) { Nil }
- method delete_pos(Any:U: $pos) { Nil }
+ proto method delete_key(|) { * }
+ multi method delete_key(Any:U: $key) { Nil }
+ multi method delete_key(Any:D: $key) {
+ fail "Can not remove values from a {self.^name}";
+ }
+
+ proto method delete_pos(|) { * }
+ multi method delete_pos(Any:U: $pos) { Nil }
+ multi method delete_pos(Any:D: $pos) {
+ fail "Can not remove elements from a {self.^name}";
+ }
+
method list() {
nqp::p6list(
self.DEFINITE ?? nqp::list(self) !! nqp::list(), List, Mu

0 comments on commit 11bada4

Please sign in to comment.