Skip Menu |
Report information
Id: 129214
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: roam [at]

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)

Subject: Initialization of variables explicitly declared as Hash[...]
Download (untitled) / with headers
text/plain 1.7k
Hi, 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 Thanks in advance for looking into this! G'luck, Peter

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at