You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to write a function returning Hash[Array[Str]], I came up against what looks like two related problems. All of this is with both 2016.08.1 and a current one - "This is Rakudo version 2016.08.1-116-gf648d3b built on MoarVM version 2016.08-35-g5108035".
First of all, if a variable is declared, but not initialized, it seems that some kind of initialization is delayed until an assignment is made and then a type check breaks. Here's an example:
#!/usr/bin/env perl6
use v6.c;
my Hash[Int] $data;
say 'Created, not initialized yet';
dd $data;
say 'About to initialize it...';
$data<key> = 5;
say 'We never get here, do we?';
dd $data;
The output is:
[roam@straylight ~/lang/perl/misc/rt/hash/01-init]$ perl6 hash-init.p6
Created, not initialized yet
Hash[Int] $data = Hash[Int]
About to initialize it...
Type check failed in assignment to $data; expected Hash[Int] but got Hash (${})
in block <unit> at hash-init.p6 line 11
And this leads almost directly to the second problem. I tried to work around this message by initializing the hash at creation time, and this seems to actually lose the value type constraint! Here's an example:
#!/usr/bin/env perl6
use v6.c;
my Hash[Int] $data .= new();
say 'Created and initialized';
dd $data;
say 'About to assign to it...';
$data<key> = 3/5;
say 'So did we really store a Rat into a hash of Ints?';
dd $data;
dd $data<key>;
And the output is:
[roam@straylight ~/lang/perl/misc/rt/hash/02-weird-types]$ perl6 hash-int-rat.p6
Created and initialized
Hash[Int] $data = (my Int %)
About to assign to it...
So did we really store a Rat into a hash of Ints?
Hash[Int] $data = (my Int % = :key(0.6))
Rat <element> = 0.6
Migrated from rt.perl.org#129214 (status was 'new')
Searchable as RT129214$
The text was updated successfully, but these errors were encountered: