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

"of" type constraint inconsistently applied #4555

Closed
p6rt opened this issue Sep 19, 2015 · 6 comments
Closed

"of" type constraint inconsistently applied #4555

p6rt opened this issue Sep 19, 2015 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Sep 19, 2015

Migrated from rt.perl.org#126107 (status was 'resolved')

Searchable as RT126107$

@p6rt
Copy link
Author

p6rt commented Sep 19, 2015

From zefram@fysh.org

If a scalar variable is given a type constraint using the "of" syntax,
the type constraint is not consistently applied, where the default value
is concerned​:

$ ./perl6 -e 'my $a of Int; say $a'
(Any)
$ ./perl6 -e 'my $a of Int; $a = Any; say $a'
Type check failed in assignment to '$a'; expected 'Int' but got 'Any'
  in block <unit> at -e​:1
$ ./perl6 -e 'my $a of Int; $a = $a; say $a'
Type check failed in assignment to '$a'; expected 'Int' but got 'Any'
  in block <unit> at -e​:1
$ ./perl6 -e 'my $a of Int; $a = 3; say $a; $a = Nil; say $a'
3
(Any)
$ ./perl6 -e 'my $a of Int; $a = 3; say $a; $a = Any; say $a'
3
Type check failed in assignment to '$a'; expected 'Int' but got 'Any'
  in block <unit> at -e​:1
$ ./perl6 -e 'my $a of Int is default(Any); say $a'
===SORRY!=== Error while compiling -e
Type check failed in assignment to '$a'; expected 'Int' but got 'Any'
at -e​:1

General pattern​: any attempt to explicitly put an Any value in $a
correctly fails, but the variable will merrily use Any as its default
default value, and setting it to this default via Nil assignment works.
It is presumably intended that the variable's default value should always
conform to the type constraint, even where it is determined implicitly.

-zefram

@p6rt
Copy link
Author

p6rt commented Sep 21, 2015

From zefram@fysh.org

Extended case​: if the "of" clause comes after an "is default" clause,
then the explicit default is not subjected to the type constraint.
Other behaviour remains the same.

$ ./perl6 -e 'my $a is default("foo") of Int; say $a'
foo
$ ./perl6 -e 'my $a is default("foo") of Int; $a = $a; say $a'
Type check failed in assignment to '$a'; expected 'Int' but got 'Str'
  in block <unit> at -e​:1
$ ./perl6 -e 'my $a is default("foo") of Int; $a = 3; say $a; $a = Nil; say $a'
3
foo

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

From @AlexDaniel

All of these were fixed (2017.11,HEAD(e5b660e)).

Strings give compile-time errors, putting Any into something results in an Int. Curious minds can ask bisectable for details.

「testneeded」

On 2015-09-20 17​:26​:00, zefram@​fysh.org wrote​:

Extended case​: if the "of" clause comes after an "is default" clause,
then the explicit default is not subjected to the type constraint.
Other behaviour remains the same.

$ ./perl6 -e 'my $a is default("foo") of Int; say $a'
foo
$ ./perl6 -e 'my $a is default("foo") of Int; $a = $a; say $a'
Type check failed in assignment to '$a'; expected 'Int' but got 'Str'
in block <unit> at -e​:1
$ ./perl6 -e 'my $a is default("foo") of Int; $a = 3; say $a; $a =
Nil; say $a'
3
foo

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 12, 2017

From @zoffixznet

Tests​: Raku/roast@785446408e
  Raku/roast@0d79eda3dc

@p6rt p6rt closed this as completed Dec 12, 2017
@p6rt
Copy link
Author

p6rt commented Dec 12, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant