Skip to content

Commit

Permalink
Make PARAMETRIZE_TYPE errors a bit less LTA
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 8, 2013
1 parent 5b9d80b commit c52f245
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/core/Array.pm
Expand Up @@ -141,8 +141,13 @@ class Array {
}
# XXX some methods to come here...
}
method PARAMETERIZE_TYPE(Mu $t) {
self but TypedArray[$t.WHAT]
method PARAMETERIZE_TYPE(Mu $t, |c) {
if c.elems == 0 {
self but TypedArray[$t.WHAT]
}
else {
die "Can only type-constraint Array with [ValueType]"
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/core/Hash.pm
Expand Up @@ -280,9 +280,15 @@ my class Hash {
}
}
method PARAMETERIZE_TYPE(Mu $t, |c) {
c.elems ??
self but TypedHash[$t.WHAT, c[0]] !!
if c.elems == 0 {
self but TypedHash[$t.WHAT]
}
elsif c.elems == 1 {
self but TypedHash[$t.WHAT, c[0]]
}
else {
die "Can only type-constraint Hash with [ValueType] or [ValueType,KeyType]";
}
}
}

Expand Down

0 comments on commit c52f245

Please sign in to comment.