Skip to content

Commit

Permalink
Add coercion exceptions
Browse files Browse the repository at this point in the history
The base `X::Coerce` and `X::Coerce::Impossible`.
  • Loading branch information
vrurg committed Nov 15, 2020
1 parent f2d7328 commit 2675813
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core.c/Exception.pm6
Expand Up @@ -873,6 +873,20 @@ my class X::Comp::BeginTime does X::Comp {
}
}

my class X::Coerce is Exception {
has Mu:U $.target-type;
has Mu:U $.from-type;
method message() {
"from " ~ $!from-type.^name ~ " into " ~ $!target-type.^name
}
}

my class X::Coerce::Impossible is X::Coerce {
method message() {
"Impossible coercion " ~ callsame
}
}

# XXX a hack for getting line numbers from exceptions from the metamodel
my class X::Comp::AdHoc is X::AdHoc does X::Comp {
method is-compile-time(--> True) { }
Expand Down Expand Up @@ -2955,6 +2969,10 @@ nqp::bindcurhllsym('P6EX', BEGIN nqp::hash(
-> Mu $got is raw, Mu $expected is raw {
X::TypeCheck::Return.new(:$got, :$expected).throw;
},
'X::Coerce::Impossible',
-> Mu $target-type is raw, Mu $from-type is raw {
X::Coerce::Impossible.new(:$target-type, :$from-type).throw;
},
'X::Assignment::RO',
-> $value is raw = "value" {
X::Assignment::RO.new(:$value).throw;
Expand Down

0 comments on commit 2675813

Please sign in to comment.