You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
On Sun, 20 Sep 2015 09:17:21 -0700, zefram@fysh.org wrote:
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.
Migrated from rt.perl.org#126117 (status was 'open')
Searchable as RT126117$
The text was updated successfully, but these errors were encountered: