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

Owner: Nobody
Requestors: zefram [at] fysh.org
Cc:
AdminCc:

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



To: rakudobug [...] perl.org
Subject: [BUG] Scalar:D variable botches type check
From: Zefram <zefram [...] fysh.org>
Date: Wed, 15 Jun 2016 07:01:35 +0100
The Scalar:D type constraint doesn't work on a variable: Show quoted text
> my $v = 3 > my $s = $v.VAR > $s.WHAT.say
(Scalar) Show quoted text
> $s.DEFINITE
True Show quoted text
> my Scalar:D $x = $s
Type check failed in assignment to $x; expected Scalar:D but got Int (3) in block <unit> at <unknown file> line 1 $s is a defined Scalar object, so should satisfy the Scalar:D type constraint, but it is being rejected. The error message erroneously refers to the value contained in the Scalar. As this suggests, if the Scalar happens to contain a defined Scalar object (such as by "$v = $s"), then the variable initialisation succeeds. The same goes for assignments to the Scalar:D variable after successful creation: the assignment is permitted iff the value being assigned is a defined Scalar that contains a defined Scalar value (regardless of the value contained in the inner Scalar). A Scalar:D type constraint on a subroutine parameter works fine: it accepts a value iff the value is a defined Scalar (regardless of the value that the Scalar contains). -zefram
Subject: [perl #128407] [BUG] Scalar:D variable botches type check
From: Zefram <zefram [...] fysh.org>
To: perl6 via RT <perl6-bugs-followup [...] perl.org>
Date: Wed, 15 Jun 2016 07:59:30 +0100
Download (untitled) / with headers
text/plain 808b
There is related misbehaviour that causes variables to accept values that they should reject: Show quoted text
> my $v = 5
5 Show quoted text
> my $s = $v.VAR
5 Show quoted text
> my Int:D $x = $s
5 Show quoted text
> $x.WHAT.say
(Scalar) Show quoted text
> $v = Int > my Any:U $x = $s > $x.DEFINITE
True The general pattern is that if a variable has a type constraint that includes a definiteness qualifier, and an attempt is made to assign a Scalar value to the variable, then the type constraint gets applied to the value contained in the Scalar rather than to the Scalar itself. If the type check against that value passes, then the Scalar value is assigned to the variable, regardless of whether the Scalar itself satisfies the type constraint. Type constraints that do not have definiteness qualifiers work as expected, and so do type constraints on subroutine parameters. -zefram


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