Skip Menu |
Report information
Id: 126117
Status: open
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)



Subject: [BUG] defined value as type constraint is accepted and doesn't work
Date: Sun, 20 Sep 2015 17:17:01 +0100
From: Zefram <zefram [...] fysh.org>
To: rakudobug [...] perl.org
How nice to be able to use a constant declaration to give a local name to a (possibly complex) type: $ ./perl6 -e 'constant T = Int; my T $a = 3; say $a' 3 But because the constant declaration accepts any kind of defining expression, and gives the value a bareword name, it makes it syntactically possible to use something other than a type object as a type constraint. This doesn't work so well: $ ./perl6 -e 'constant T = 3; my T $a; say $a; $a = 3; say $a' 3 Type check failed in assignment to '$a'; expected 'Int' but got 'Int' in block <unit> at -e:1 The error message on assignment is nonsensical, because the types it complains are mismatching are identical. The only value that can be successfully assigned is Nil, which leaves the variable holding the same (default) value. The same effect can be seen without the user making eir own constant declaration by using the predefined constant i. Presumably using a defined value (anything other than a type object) as a type constraint should be a semantic error. -zefram
Download (untitled) / with headers
text/plain 1.1k
On Sun, 20 Sep 2015 09:17:21 -0700, zefram@fysh.org wrote: Show quoted text
> Presumably using a defined value (anything other than a type object) > as a type constraint should be a semantic error.
It does throw a compile-time error for the `my` declaration now, however the error message is not appropriate: ➜ constant T = 3; my T $a; say $a; $a = 3; say $a; ===SORRY!=== Error while compiling: Variable definition of type Int (implicit : by pragma) requires an initializer ------> constant T = 3; my T $a⏏; say $a; $a = 3; say $a; expecting any of: constraint According to bisectable¹, this new behavior was introduced by a commit² by FROGGS in Oct 2015. That commit implemented Type:D and Type:U types, and the "implicit : by pragma" part of the error message is actually meant to print something like "implicit :D by pragma", except apparently it also catches the unrelated issue of this RT. It should be made to print a more appropriate message in this case. Marking this as an LTA ticket. --- [1] https://gist.github.com/Whateverable/a6f61fac5114f64747a8a9d913e2f3d7 [2] https://github.com/rakudo/rakudo/commit/80a3d07


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