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

Owner: Nobody
Requestors: moritz <moritz.lenz [at] googlemail.com>
Cc:
AdminCc:

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



Subject: Parametric types and recursion lead to attribute or accessor confusion
Date: Sat, 26 Nov 2016 22:30:38 +0100
To: rakudobug [...] perl.org
From: Moritz Lenz <moritz [...] faui2k3.org>
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/


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