There is related misbehaviour that causes variables to accept values
that they should reject:

> my $v = 5
5
> my $s = $v.VAR
5
> my Int:D $x = $s
5
> $x.WHAT.say
(Scalar)
> $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

Reply via email to