Skip to content

Commit

Permalink
Make faulty variable trait declarations nicer using new Exception
Browse files Browse the repository at this point in the history
Still wondering what would be needed to actually show the line of code like
some other errors do.
  • Loading branch information
lizmat committed Jul 27, 2013
1 parent 0d3c78c commit 296da02
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/core/Variable.pm
@@ -1,3 +1,7 @@
# for our tantrums
my class X::Comp::NYI { ... };
my class X::Comp::Trait { ... };

# Variable traits come here, not in traits.pm, since we declare Variable # Variable traits come here, not in traits.pm, since we declare Variable
# in the setting rather than BOOTSTRAP. # in the setting rather than BOOTSTRAP.


Expand All @@ -10,10 +14,27 @@ my class Variable {


# "is" traits # "is" traits
multi trait_mod:<is>(Variable:D $v, |c ) { multi trait_mod:<is>(Variable:D $v, |c ) {
die "You cannot say 'is {c.hash.keys}' in a variable declaration."; X::Comp::Trait.new(
file => $?FILE,
line => $?LINE,
column => 1,
is-compile-time => True,

type => 'is',
subtype => c.hash.keys[0],
declaring => 'variable',
highexpect => <TypeObject default dynamic>,
).throw;
} }
multi trait_mod:<is>(Variable:D $v, Mu:U $is ) { multi trait_mod:<is>(Variable:D $v, Mu:U $is ) {
die "Variable trait 'is {$is.perl}' has not yet been implemented."; X::Comp::NYI.new(
file => $?FILE,
line => $?LINE,
column => 1,
is-compile-time => True,

feature => "Variable trait 'is TypeObject'",
).throw;
} }
multi trait_mod:<is>(Variable:D $v, :$default!) { multi trait_mod:<is>(Variable:D $v, :$default!) {
$v.var = $default; # make sure we start with the default $v.var = $default; # make sure we start with the default
Expand All @@ -31,15 +52,35 @@ multi trait_mod:<is>(Variable:D $v, :$dynamic!) {


# "of" traits # "of" traits
multi trait_mod:<of>(Variable:D $v, |c ) { multi trait_mod:<of>(Variable:D $v, |c ) {
die "You cannot say 'of {c.hash.keys}' in a variable declaration."; X::Comp::Trait.new(
file => $?FILE,
line => $?LINE,
column => 1,
is-compile-time => True,

type => 'of',
subtype => c.hash.keys[0],
declaring => 'variable',
highexpect => <TypeObject>,
).throw;
} }
multi trait_mod:<of>(Variable:D $v, Mu:U $of ) { multi trait_mod:<of>(Variable:D $v, Mu:U $of ) {
nqp::getattr($v.var, $v.var.VAR.WHAT, '$!descriptor').set_of(nqp::decont($of)); nqp::getattr($v.var, $v.var.VAR.WHAT, '$!descriptor').set_of(nqp::decont($of));
} }


# phaser traits # phaser traits
multi trait_mod:<will>(Variable:D $v, $block, |c ) { multi trait_mod:<will>(Variable:D $v, $block, |c ) {
die "You cannot say 'will {c.hash.keys}' in a variable declaration."; X::Comp::Trait.new(
file => $?FILE,
line => $?LINE,
column => 1,
is-compile-time => True,

type => 'will',
subtype => c.hash.keys[0],
declaring => 'variable',
highexpect => <begin check final init end enter leave keep undo first next last pre post catch control compose>,
).throw;
} }
multi trait_mod:<will>(Variable:D $v, $block, :$begin! ) { multi trait_mod:<will>(Variable:D $v, $block, :$begin! ) {
$v.block.add_phaser('BEGIN', $block) $v.block.add_phaser('BEGIN', $block)
Expand Down

0 comments on commit 296da02

Please sign in to comment.