Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalar:D variable botches type check #5379

Open
p6rt opened this issue Jun 15, 2016 · 2 comments
Open

Scalar:D variable botches type check #5379

p6rt opened this issue Jun 15, 2016 · 2 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Jun 15, 2016

Migrated from rt.perl.org#128407 (status was 'new')

Searchable as RT128407$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jun 15, 2016

From zefram@fysh.org

The Scalar​:D type constraint doesn't work on a variable​:

my $v = 3
my $s = $v.VAR
$s.WHAT.say
(Scalar)
$s.DEFINITE
True
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

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jun 15, 2016

From zefram@fysh.org

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.