Skip Menu |
Report information
Id: 131493
Status: rejected
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: mt1957 [at] gmail.com
Cc:
AdminCc:

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



Subject: changed type of variable
To: rakudobug [...] perl.org
Date: Sat, 3 Jun 2017 11:04:23 +0200
From: Marcel Timmerman <mt1957 [...] gmail.com>
Download (untitled) / with headers
text/plain 551b
Hi, In Rakudo version 2017.05-338-gaca1929 built on MoarVM version 2017.05-25-g62bc54e implementing Perl 6.c I saw that a type could be changed through an assignment which It should not do. In REPL; Show quoted text
> my Str $s = IntStr.new(12,'12');
12 Show quoted text
> $s.WHAT
(IntStr) Show quoted text
>
The type IntStr should be coerced into Str. A second example happened in my code and golfed in REPL Show quoted text
> sub s (Str :$str) {say $str.WHAT}
sub s (Str :$str) { #`(Sub|89412592) ... } Show quoted text
> s(:str<1>)
(IntStr) Show quoted text
> s(:str<a>)
(Str) The type should stay as it was defined I think. Marcel
Well,

say IntStr ~~ Str   # True

In other words, IntStr *is* a Str.

What I find interesting, however, is this difference:

sub s (Str() :$str) {say $str.WHAT}; s(:str<1>) # IntStr
sub s (Str :$str) {say $str.Str.WHAT}; s(:str<1>) # Str

I would have expected the same output in both cases.

On 2017-06-03 02:05:49, mt1957@gmail.com wrote:
Show quoted text
> Hi,
>
> In Rakudo version 2017.05-338-gaca1929 built on MoarVM version
> 2017.05-25-g62bc54e
> implementing Perl 6.c I saw that a type could be changed through an
> assignment which It should not do. In REPL;
>
>
> > my Str $s = IntStr.new(12,'12');
> 12
> > $s.WHAT
> (IntStr)
> >
>
> The type IntStr should be coerced into Str. A second example happened in
> my code and golfed in REPL
>
>
>
> > sub s (Str :$str) {say $str.WHAT}
> sub s (Str :$str) { #`(Sub|89412592) ... }
> > s(:str<1>)
> (IntStr)
> > s(:str<a>)
> (Str)
>
>
> The type should stay as it was defined I think.
> Marcel


Date: Sat, 3 Jun 2017 12:52:41 +0200
From: Marcel Timmerman <mt1957 [...] gmail.com>
Subject: Re: [perl #131493] changed type of variable
To: perl6-bugs-followup [...] perl.org
Download (untitled) / with headers
text/plain 119b
On 06/03/2017 11:36 AM, Aleks-Daniel Jakimenko-Aleksejev via RT wrote: Show quoted text
> say IntStr ~~ Str
Show quoted text
> say Str ~~ IntStr
False
To: perl6-bugs-followup [...] perl.org
Subject: Re: [perl #131493] changed type of variable
From: Marcel Timmerman <mt1957 [...] gmail.com>
Date: Sat, 3 Jun 2017 13:09:50 +0200
Download (untitled) / with headers
text/plain 451b
On 06/03/2017 11:36 AM, Aleks-Daniel Jakimenko-Aleksejev via RT wrote: Show quoted text
> sub s (Str() :$str) {say $str.WHAT}; s(:str<1>) # IntStr > sub s (Str :$str) {say $str.Str.WHAT}; s(:str<1>) # Str
I think the last one is coerced explicitly. Btw I didn't know about 'Str() :$str' specification. What does it do? The previous mail about the type test 'say Str ~~ IntStr' I meant that this is the test what the coercion to Str should force isn't it? Marcel
Subject: Re: [perl #131493] changed type of variable
To: perl6-bugs-followup [...] perl.org
From: Marcel Timmerman <mt1957 [...] gmail.com>
Date: Sat, 3 Jun 2017 16:51:01 +0200
Download (untitled) / with headers
text/plain 163b
After some discussion I've understood that I have to do some homework and that this bug can be closed. Thanks Jnhtn and Araraloren for your help Regards, Marcel
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 589b
On Sat, 03 Jun 2017 07:52:09 -0700, mt1957@gmail.com wrote: Show quoted text
> this bug can be closed
OK. Closing. On Sat, 03 Jun 2017 02:36:12 -0700, alex.jakimenko@gmail.com wrote: Show quoted text
> Well, > > say IntStr ~~ Str # True > > In other words, IntStr *is* a Str. > > What I find interesting, however, is this difference: > > sub s (Str() :$str) {say $str.WHAT}; s(:str<1>) # IntStr > sub s (Str :$str) {say $str.Str.WHAT}; s(:str<1>) # Str > > I would have expected the same output in both cases.
It's a bit involved. I opened a separate @LARRY ticket: https://rt.perl.org/Ticket/Display.html?id=131505


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