Permalink
Browse files

Enable Hash[TVal,TKey].new to work (for lizmat++).

This patch updates Hash.new so that it correctly understands
how to create typed hashes from a parameterized Hash type object.
In particular, `Hash[Str,Int].new` will create a hash constrained
to Int keys and Str values.

This patch at least partially addresses
perl6/specs#43 .

Note that this doesn't resolve the output of `.perl` on
typed hashes; that's a different problem (having to do with
the definition of `Hash.perl` and/or `TypedHash.perl`).
And `.perl` is due for some redesign as well, see
perl6/specs#6 .
  • Loading branch information...
1 parent c947f78 commit 90f3beeceb73cf731d4834aa82974a4c3f2f7516 @pmichaud pmichaud committed Jun 13, 2013
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/core/Hash.pm
View
@@ -3,7 +3,11 @@ my class X::Hash::Store::OddNumber { ... }
my class Hash {
# Has attributes and parent EnumMap declared in BOOTSTRAP
- method new(*@args) { @args.hash }
+ method new(*@args) {
+ my %h := nqp::create(self);
+ %h.STORE(@args) if @args;
+ %h;
+ }
multi method at_key(Hash:D: $key is copy) is rw {
my Mu $storage := nqp::defined(nqp::getattr(self, EnumMap, '$!storage')) ??

0 comments on commit 90f3bee

Please sign in to comment.