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

Owner: Nobody
Requestors: moritz <moritz.lenz+perl [at] gmail.com>
Cc:
AdminCc:

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



Subject: a constant hash does not coerce its RHS correctly
Date: Fri, 23 Mar 2012 14:39:47 +0100
To: rakudobug [...] perl.org
From: Moritz Lenz <moritz [...] faui2k3.org>
Download (untitled) / with headers
text/plain 396b
14:37 < moritz> nom: constant %h = 1, 2; say %h.WHAT 14:37 <+p6eval> rakudo 4a247b: OUTPUT«Parcel()␤» should be Hash(), of course 14:37 * moritz submits rakudobug 14:37 < jnthn> Hm :) 14:38 * jnthn wonders how that one is meant to work :) 14:38 < jnthn> Though, constant %h = { ... } gets you what you want. 14:38 < moritz> maybe like constant %h := (my % = ...) 14:38 < jnthn> Or that.
Download (untitled) / with headers
text/plain 1.9k
<japhb_> r: constant %foo = ().list; say %foo.perl; <camelia> rakudo-parrot 180fca, rakudo-jvm 180fca: OUTPUT«().list␤» <japhb_> ^^ Is that a bug, or me being silly? <timotimo> it seems like both <jnthn> japhb_: It's me not really grokking how constant is meant to work and wanting a model rather than just hacking something... :) <jnthn> japhb_: So right now it doesn't impose any context or check anything... <japhb_> Ah. <tadzik> r: my %foo = ("a", 5); say %foo.perl <camelia> rakudo-parrot 180fca, rakudo-jvm 180fca: OUTPUT«("a" => 5).hash␤» <tadzik> looks legit to me <tadzik> r: my %foo = ("a", 5).list; say %foo.perl <camelia> rakudo-parrot 180fca, rakudo-jvm 180fca: OUTPUT«("a" => 5).hash␤» <tadzik> oh <jnthn> Oh...it does .hash it? <tadzik> well, it's a hash container <jnthn> I didn't now that :) <tadzik> I'd expect that :) <tadzik> but constant doesn't trigger it <jnthn> Right, I just didn't think that it'd been tweaked to do it. <jnthn> Oh...sorry, you wrote my <jnthn> And I read constant. <jnthn> Well, yeah, we could simply .list or .hash the RHS depending on sigil <tadzik> r: my constant %foo = ("a", 5).list; say %foo.perl <camelia> rakudo-parrot 180fca, rakudo-jvm 180fca: OUTPUT«("a", 5).list␤» <tadzik> best of both worlds? :P <masak> r: my %h = 4 <camelia> rakudo-parrot 180fca: OUTPUT«Odd number of elements found where hash expected [...] <camelia> ..rakudo-jvm 180fca: OUTPUT«Odd number of elements found where hash expected [...] <masak> re constant hash: I'd very much expect 'constant' to give the above warning just as much as 'my'. * masak submits rakudobug <FROGGS> masak++ <tadzik> r: constant %h = 4 <camelia> rakudo-parrot 180fca, rakudo-jvm 180fca: ( no output ) <tadzik> phihihi <jnthn> That one is, like, so already in RT.. <masak> I will look for it. <masak> p: constant %h = 1, 2; say %h.WHAT <camelia> rakudo-parrot 180fca: OUTPUT«(Parcel)␤» <masak> that's https://rt.perl.org/Ticket/Display.html?id=111944 <masak> I will attach the current complaint to it.
Download (untitled) / with headers
text/plain 347b
13:08 <diakopter> m: constant %h = 1, 2; say %h.WHAT 13:08 <camelia> rakudo-moar 61d231: OUTPUT«===SORRY!=== Error while compiling /tmp/NxuZQLpyx_␤Type check failed in constant declaration of %h; expected Associative but got List (List)␤at /tmp/NxuZQLpyx_:1␤------> constant %h = 1, 2⏏; say %h.WHAT␤»
Download (untitled) / with headers
text/plain 583b
On Thu Apr 07 10:10:22 2016, diakopter wrote: Show quoted text
> 13:08 <diakopter> m: constant %h = 1, 2; say %h.WHAT > 13:08 <camelia> rakudo-moar 61d231: OUTPUT«===SORRY!=== Error while > compiling /tmp/NxuZQLpyx_␤Type check failed in > constant declaration of %h; expected Associative but > got List (List)␤at /tmp/NxuZQLpyx_:1␤------> > constant %h = 1, 2⏏; say %h.WHAT␤»
This is not correct behavior; hash assignment is meant to be coercive, and I see no indication that doing it in a constant is supposed to be any diferent than in a regular my.
Download (untitled) / with headers
text/plain 570b
Constant @ variables behave differently from their `my` counterparts as well: ➜ constant @a = 1..3; ➜ say @a.WHAT; (List) Maybe the default types (which assignment coerces to) are supposed to be: | @ | % ----------+-------+------ constant: | List | Map my: | Array | Hash ...and the `constant %` case just doesn't work correctly yet. It would make sense, because List/Map are the immutable counterparts of Array/Hash. But the design docs don't have much on constants, so I'm just guessing at the original intentions.


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