Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make error messages on "is default/dynamic" better
This is really the result of trying to make "is default/dynamic" work
on shaped arrays.  This has failed, because at the moment the trait
code is run, the shaped array does not have a descriptor initialized
yet.  Which means we're trying to look up attributes in a type object,
and thus fail.
  • Loading branch information
lizmat committed Jan 2, 2016
1 parent e63d878 commit 3ea4dff
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/core/Variable.pm
Expand Up @@ -24,6 +24,15 @@ my class Variable {
?? -> { block(nqp::atkey(nqp::ctxcaller(nqp::ctxcaller(nqp::ctxcaller(nqp::ctx()))), self.name)) }
!! -> { block(nqp::atkey(nqp::ctxcaller(nqp::ctx()), self.name)) }
}

submethod native(Mu $what) {
my $name := $what.perl;
$name.starts-with('array') || $name eq 'Mu'
?? $name
!! $name.ends-with('LexRef')
?? $name.substr(0,3).lc
!! '';
}
}

# "is" traits
Expand All @@ -43,11 +52,16 @@ multi sub trait_mod:<is>(Variable:D $v, Mu :$default!) {
{
$descriptor := nqp::getattr($var, $what.^mixin_base, '$!descriptor');
CATCH {
nqp::istype($default,Whatever)
?? $v.throw( 'X::Comp::NYI',
:feature<is default(*) on natives> )
!! $v.throw( 'X::Comp::Trait::NotOnNative',
:type<is>, :subtype<default> ); # can't find out native type yet
my $native = $v.native($what);
$native
?? nqp::istype($default,Whatever)
?? $v.throw('X::Comp::NYI',
:feature("is default(*) on native $native"))
!! $v.throw( 'X::Comp::Trait::NotOnNative',
:type<is>, :subtype<default>,
:native($native eq 'Mu' ?? ''!! $native )) # yuck
!! $v.throw('X::Comp::NYI',
:feature("is default on shaped $what.perl()"))
}
}

Expand All @@ -63,14 +77,16 @@ multi sub trait_mod:<is>(Variable:D $v, Mu :$default!) {
multi sub trait_mod:<is>(Variable:D $v, :$dynamic!) {
my $var := $v.var;
my $what := $var.VAR.WHAT;
{ nqp::getattr(
$var,
$what.^mixin_base,
'$!descriptor',
).set_dynamic($dynamic);
{
nqp::getattr($var,$what.^mixin_base,'$!descriptor').set_dynamic($dynamic);
CATCH {
$v.throw( 'X::Comp::Trait::NotOnNative',
:type<is>, :subtype<dynamic> ); # can't find out native type yet
my $native = $v.native($what);
$native
?? $v.throw( 'X::Comp::Trait::NotOnNative',
:type<is>, :subtype<dynamic>,
:native($native eq 'Mu' ?? ''!! $native )) # yuck
!! $v.throw('X::Comp::NYI',
:feature("is dynamic on shaped $what.perl()"))
}
}
}
Expand Down

0 comments on commit 3ea4dff

Please sign in to comment.