Skip to content

Commit

Permalink
Streamline handling of bind/delete on native arrays
Browse files Browse the repository at this point in the history
- Introduce X::Delete typed error message and use that
- Throw an X::Bind on trying to bind: please note that this is
  runtime and at that point it is impossible to get the name of
  the native array being accessed, so X::Bind::NativeType can
  not be used for that.
  • Loading branch information
lizmat committed Nov 14, 2020
1 parent 2f3de2f commit adeff7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/core.c/Exception.pm6
Expand Up @@ -1434,6 +1434,15 @@ my class X::Adverb is Exception {
method nogo { @!nogo.sort }
}

my class X::Delete is Exception {
has $.target;
method message() {
$.target.defined
?? "Cannot delete from $.target"
!! 'Cannot delete from this left-hand side'
}
}

my class X::Bind is Exception {
has $.target;
method message() {
Expand Down
14 changes: 11 additions & 3 deletions src/core.c/native_array.pm6
@@ -1,4 +1,5 @@
my class X::MustBeParametric { ... }
my class X::Delete { ... }
my class X::MustBeParametric { ... }
my class X::TooManyDimensions { ... }
my class X::TypeCheck::Assignment { ... }

Expand Down Expand Up @@ -1947,6 +1948,13 @@ my class array does Iterable {
}

role shapedarray does Rakudo::Internals::ShapedArrayCommon {
method BIND-POS(|) {
X::Bind.new(target => 'a natively typed shaped array').throw
}
method DELETE-POS(|) {
X::Delete.new(target => 'a natively typed shaped array').throw
}

method shape() {
my $idims := nqp::dimensions(self);
my $odims := nqp::create(IterationBuffer);
Expand Down Expand Up @@ -3593,10 +3601,10 @@ my class array does Iterable {
}

method BIND-POS(|) {
die "Cannot bind to a natively typed array";
X::Bind.new(target => 'a natively typed array').throw
}
method DELETE-POS(|) {
die "Cannot delete from a natively typed array";
X::Delete.new(target => 'a natively typed array').throw
}

proto method ASSIGN-POS(|) {*} # Hide candidates from Any
Expand Down

0 comments on commit adeff7d

Please sign in to comment.