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

Parametric types and recursion lead to attribute or accessor confusion #5813

Open
p6rt opened this issue Nov 26, 2016 · 1 comment
Open

Parametric types and recursion lead to attribute or accessor confusion #5813

p6rt opened this issue Nov 26, 2016 · 1 comment

Comments

@p6rt
Copy link

@p6rt p6rt commented Nov 26, 2016

Migrated from rt.perl.org#130183 (status was 'new')

Searchable as RT130183$

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 26, 2016

From @moritz

In this small example, I get an exception where I don't expect one​:

role LL[​::T] {
  has T $.item;
  has LL[T] $.next;
  method visit(&c) {
  c($.item);
  $.next.visit(&c) if $.next;
  }
}

my $t = LL[Int].new(
  item => 5,
  next => LL[Int].new( item => 4 ),
);
say $t.perl;
$t.visit(&say);

Output​:

LL[Int].new(item => 5, next => LL[Int].new(item => 4, next => LL[T]))
5
No such method 'visit' for invocant of type 'Int'
  in method visit at role-param-bug.p6 line 6
  in block <unit> at role-param-bug.p6 line 15

It calls method visit on an Int, but $.next is a LL[Int], as the .perl
output confirms.

When I add a 'dd $.next' before the dying recursion call, it reports
$.next as Int 4. Which the type constraint shouldn't even allow as value
for $.next.

Other observations​:

* changing the name of the attribute doesn't make a difference
* changing $.next.visit(&c) to $!next.visit(&c) makes the error go away.

Cheers,
Moritz

--
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.