Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Good error on parameterizing a non-parametric.
Now it shows what went wrong and where, rather than just a method not
found error.
  • Loading branch information
jnthn committed Jul 15, 2015
1 parent d378509 commit e4077e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Perl6/Actions.nqp
Expand Up @@ -3988,7 +3988,7 @@ Compilation unit '$file' contained the following violations:
}
if $need_role {
if nqp::existskey(%*PARAM_INFO, 'nominal_type') {
%*PARAM_INFO<nominal_type> := $*W.parameterize_type_with_args(
%*PARAM_INFO<nominal_type> := $*W.parameterize_type_with_args($/,
$role_type, [%*PARAM_INFO<nominal_type>], nqp::hash());
}
else {
Expand Down Expand Up @@ -6191,7 +6191,7 @@ Compilation unit '$file' contained the following violations:
$<accept> ?? $<accept>.ast !! $*W.find_symbol(['Any']));
}
elsif $<typename> {
$type := $*W.parameterize_type_with_args($type,
$type := $*W.parameterize_type_with_args($/, $type,
[$<typename>.ast], hash());
}
make $type;
Expand Down
17 changes: 10 additions & 7 deletions src/Perl6/World.nqp
Expand Up @@ -1180,9 +1180,9 @@ class Perl6::World is HLL::World {
my $vtype := @value_type[0];
my $base_type_name := nqp::objprimspec($vtype) ?? 'array' !! 'Array';
%info<container_base> := self.find_symbol([$base_type_name]);
%info<container_type> := self.parameterize_type_with_args(
%info<container_type> := self.parameterize_type_with_args($/,
%info<container_base>, [$vtype], nqp::hash());
%info<bind_constraint> := self.parameterize_type_with_args(
%info<bind_constraint> := self.parameterize_type_with_args($/,
%info<bind_constraint>, [$vtype], nqp::hash());
%info<value_type> := $vtype;
%info<default_value> := $vtype;
Expand Down Expand Up @@ -1232,9 +1232,9 @@ class Perl6::World is HLL::World {
self.throw($/, 'X::Comp::NYI',
feature => "native value types for hashes");
}
%info<container_type> := self.parameterize_type_with_args(
%info<container_type> := self.parameterize_type_with_args($/,
%info<container_base>, @value_type, nqp::hash());
%info<bind_constraint> := self.parameterize_type_with_args(
%info<bind_constraint> := self.parameterize_type_with_args($/,
%info<bind_constraint>, @value_type, nqp::hash());
%info<value_type> := @value_type[0];
%info<default_value> := @value_type[0];
Expand All @@ -1250,7 +1250,7 @@ class Perl6::World is HLL::World {
%info<container_type> := %info<container_base>;
%info<bind_constraint> := self.find_symbol(['Callable']);
if @value_type {
%info<bind_constraint> := self.parameterize_type_with_args(
%info<bind_constraint> := self.parameterize_type_with_args($/,
%info<bind_constraint>, [@value_type[0]], nqp::hash());
}
%info<value_type> := %info<bind_constraint>;
Expand Down Expand Up @@ -2457,13 +2457,16 @@ class Perl6::World is HLL::World {
}
}

self.parameterize_type_with_args($role, @pos_args, %named_args);
self.parameterize_type_with_args($/, $role, @pos_args, %named_args);
}

# Curries a role with the specified arguments.
method parameterize_type_with_args($role, @pos_args, %named_args) {
method parameterize_type_with_args($/, $role, @pos_args, %named_args) {
# Make the curry right away and add it to the SC.
if @pos_args || %named_args {
unless nqp::can($role.HOW, 'parameterize') {
self.throw($/, 'X::NotParametric', type => $role);
}
my $curried := $role.HOW.parameterize($role, |@pos_args, |%named_args);
self.add_object($curried);
return $curried;
Expand Down
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -2039,4 +2039,11 @@ my class X::TooLateForREPR is X::Comp {
}
}

my class X::NotParametric is Exception {
has $.type;
method message() {
"$!type.^name() cannot be parameterized";
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit e4077e3

Please sign in to comment.