Skip Menu |
Report information
Id: 129215
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: roam [at] ringlet.net
Cc:
AdminCc:

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



Subject: Passing a Hash[...] as a parameter to an imported sub
Hi, So here's the main program: #!/usr/bin/perl6 use v6.c; use lib '.'; use trap; sub woof-local(Hash[Str:D] $data) { return $data<title>[0]; } { my %opts = title => 'Something something something dark side'; say 'Invoking the local sub...'; say woof-local(Hash[Str:D].new(%opts)); %opts<title> = "It's a trap!"; say 'Invoking the remote sub...'; say woof-remote(Hash[Str:D].new(%opts)); } And here's the trap.pm6 module: #!/usr/bin/env perl6 unit module trap; sub woof-remote(Hash[Str:D] $data) is export { return $data<title>[0]; } And here's the result of the execution: [roam@straylight ~/lang/perl/misc/rt/hash/03-param]$ perl6 hash-param.p6 Invoking the local sub... Something something something dark side Invoking the remote sub... Type check failed in binding to $data; expected Hash[Str:D] but got (my Str:D % = :title(... in sub woof-remote at /home/roam/lang/perl/misc/rt/hash/03-param/trap.pm6 (trap) line 5 in block <unit> at hash-param.p6 line 20 G'luck, Peter
Download (untitled) / with headers
text/plain 1.5k
On Tue, 06 Sep 2016 13:26:42 -0700, roam@ringlet.net wrote: Show quoted text
> Hi, > > So here's the main program: > > #!/usr/bin/perl6 > > use v6.c; > > use lib '.'; > use trap; > > sub woof-local(Hash[Str:D] $data) > { > return $data<title>[0]; > } > > { > my %opts = title => 'Something something something dark side'; > say 'Invoking the local sub...'; > say woof-local(Hash[Str:D].new(%opts)); > > %opts<title> = "It's a trap!"; > say 'Invoking the remote sub...'; > say woof-remote(Hash[Str:D].new(%opts)); > } > > And here's the trap.pm6 module: > > #!/usr/bin/env perl6 > > unit module trap; > > sub woof-remote(Hash[Str:D] $data) is export > { > return $data<title>[0]; > } > > And here's the result of the execution: > > [roam@straylight ~/lang/perl/misc/rt/hash/03-param]$ perl6 hash- > param.p6 > Invoking the local sub... > Something something something dark side > Invoking the remote sub... > Type check failed in binding to $data; expected Hash[Str:D] but got > (my Str:D % = :title(... > in sub woof-remote at /home/roam/lang/perl/misc/rt/hash/03- > param/trap.pm6 (trap) line 5 > in block <unit> at hash-param.p6 line 20 > > G'luck, > Peter
This is not particular to signature binding typechecks. It looks like an instance of a Hash[Str:D] from the calling module !~~ Hash[Str:D] in the called module in general. Fudged tests added in S11-modules/export.t in roast commit 272ce3800 Perplexingly, I was unable to replicate this failure using Test::Compile, which compiles through the ComUnit:: interface... a real 'use' statement was needed to replicate the problem.


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

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