Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
type-check fail if a macro application does not return an AST
  • Loading branch information
moritz committed Aug 27, 2012
1 parent 0be5872 commit 39cc71e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Perl6/Actions.pm
Expand Up @@ -3420,7 +3420,11 @@ class Perl6::Actions is HLL::Actions {
}
unless istype($quasi_ast, $ast_class) {
# XXX: Need to awesomeize with which type it got
$/.CURSOR.panic('Macro did not return AST');
$*W.throw('X::TypeCheck::MacroUnquote',
got => $quasi_ast,
expected => $ast_class,
symbol => ~$<identifier>,
);
}
my $past := QAST::Block.new(
:blocktype<raw>,
Expand Down Expand Up @@ -3521,7 +3525,7 @@ class Perl6::Actions is HLL::Actions {
add_macro_arguments($expr, $ast_class, @argument_quasi_asts);
}
}
my $quasi_ast := $routine(|@argument_quasi_asts);
my $quasi_ast := $*W.ex-handle($/, { $routine(|@argument_quasi_asts) });
if istype($quasi_ast, $nil_class) {
make QAST::Var.new(:name('Nil'), :scope('lexical'));
return 1;
Expand Down
9 changes: 8 additions & 1 deletion src/core/AST.pm
Expand Up @@ -17,7 +17,14 @@ my class AST {

method evaluate_unquotes(@unquote_asts) {
my $pasts := nqp::list();
for @unquote_asts { nqp::push($pasts, nqp::getattr(nqp::p6decont($_), AST, '$!past')) }
for @unquote_asts {
# TODO: find and report macro name
X::TypeCheck::MacroUnquote.new(
got => $_,
expected => AST,
).throw unless $_ ~~ AST;
nqp::push($pasts, nqp::getattr(nqp::p6decont($_), AST, '$!past'))
}
$!past.evaluate_unquotes($pasts);
}

Expand Down
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -819,6 +819,13 @@ my class X::TypeCheck::Assignment is X::TypeCheck {
}
}

my class X::TypeCheck::MacroUnquote is X::TypeCheck does X::Comp {
method message {
"Type check failed in macro application; expected {$.expected.^name} but got {$.got.^name}";
}

}

my class X::Assignment::RO is Exception {
method message {
"Cannot assign to a non-container";
Expand Down

0 comments on commit 39cc71e

Please sign in to comment.