Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a Hash[...] as a parameter to an imported sub #5645

Open
p6rt opened this issue Sep 6, 2016 · 3 comments
Open

Passing a Hash[...] as a parameter to an imported sub #5645

p6rt opened this issue Sep 6, 2016 · 3 comments

Comments

@p6rt
Copy link

p6rt commented Sep 6, 2016

Migrated from rt.perl.org#129215 (status was 'open')

Searchable as RT129215$

@p6rt
Copy link
Author

p6rt commented Sep 6, 2016

From roam@ringlet.net

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

@p6rt
Copy link
Author

p6rt commented Sep 17, 2017

From @skids

On Tue, 06 Sep 2016 13​:26​:42 -0700, roam@​ringlet.net wrote​:

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.

@p6rt
Copy link
Author

p6rt commented Sep 17, 2017

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant