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

coercive type constraint for variable inconsistently accepted #4558

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

coercive type constraint for variable inconsistently accepted #4558

p6rt opened this issue Sep 19, 2015 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Sep 19, 2015

Migrated from rt.perl.org#126111 (status was 'open')

Searchable as RT126111$

@p6rt
Copy link
Author

p6rt commented Sep 19, 2015

From zefram@fysh.org

A coercive type constraint is not permitted on a variable​:

$ ./perl6 -e 'my Int() $a; say 1'
===SORRY!=== Error while compiling -e
Coercion Int(Any) is insufficiently type-like to qualify a variable
at -e​:1
------> my Int() $a^; say 1
  expecting any of​:
  constraint

But it *is* accepted if expressed in "of" form​:

$ ./perl6 -e 'my $a of Int(); say 1'
1

But it doesn't actually work​:

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

Presumably it should be forbidden in the "of" form just as it is forbidden
in the prefix form.

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

From @AlexDaniel

Still reproducible (2017.11,HEAD(e5b660e))

On 2015-09-19 11​:15​:43, zefram@​fysh.org wrote​:

A coercive type constraint is not permitted on a variable​:

$ ./perl6 -e 'my Int() $a; say 1'
===SORRY!=== Error while compiling -e
Coercion Int(Any) is insufficiently type-like to qualify a variable
at -e​:1
------> my Int() $a^; say 1
expecting any of​:
constraint

But it *is* accepted if expressed in "of" form​:

$ ./perl6 -e 'my $a of Int(); say 1'
1

But it doesn't actually work​:

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

Presumably it should be forbidden in the "of" form just as it is forbidden
in the prefix form.

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

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

@p6rt p6rt added the Bug label Jan 5, 2020
@usev6
Copy link

usev6 commented Apr 10, 2021

If I'm not mistaken, coercive type constraints for variables do work now. (Fixed by @vrurg in the context of Raku/problem-solving#227.)

$ ./rakudo-m -e 'my Int() $a; $a = 3; say $a; dd $a'
3
Int $a = 3
$ ./rakudo-m -e 'my $a of Int(); $a = 3; say $a; dd $a'
3
Int $a = 3
$ ./rakudo-m -e 'my Int() $a; $a = "04"; say $a; dd $a'
4
Int $a = 4
$ ./rakudo-m -e 'my $a of Int(); $a = "04"; say $a; dd $a'
4
Int $a = 4
$ ./rakudo-m -e 'my Int() $a; $a = "foo"; say $a; dd $a'
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏foo' (indicated by ⏏)
  in block <unit> at -e line 1
$ ./rakudo-m -e 'my $a of Int(); $a = "foo"; say $a; dd $a'
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏foo' (indicated by ⏏)
  in block <unit> at -e line 1

We have a very similar test in roast: https://github.com/Raku/roast/blob/2b556e0aac/S12-coercion/coercion-types.t#L68-L75 (unfudged with Raku/roast@4718d3e1ef, was skipped before). That test uses my Int(Any) $x. IMHO it wouldn't hurt to add tests for my Int() $x.

Tagging 'testneeded'

@vrurg
Copy link

vrurg commented Apr 10, 2021

This case is already covered by S12-coercion/coercion-types.t. It's ok to close the issue.

@vrurg vrurg closed this as completed Apr 10, 2021
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

3 participants