This was fixed in (2015-11-18)
https://github.com/rakudo/rakudo/commit/06729d91e6e2d0c96ee700012827677ee518b737

$ perl6 -e 'my Int $a of Str; say "hi"'
===SORRY!=== Error while compiling -e
Str not allowed here; variable list already declared with type Int
at -e:1
------> my Int $a of Str⏏; say "hi"
expecting any of:
constraint


$ perl6 -e 'my Int $a of Str is default("z") of Rat; say "hi"'
===SORRY!=== Error while compiling -e
Str not allowed here; variable list already declared with type Int
Rat not allowed here; variable list already declared with type Str
Default value 'z' will never bind to a parameter of type Rat
at -e:1


The last one is weirdly explicit, but that's good enough I think. Too much
garbage in, some garbage out.

「testneeded」

On 2015-09-20 12:00:36, zef...@fysh.org wrote:
> S02 says this will produce a compiler error:
>
> $ ./perl6 -e 'my Int $a of Str; say "hi"'
> hi
>
> The actual result is that the "of" type is used, and the prefix type
> is mostly ignored. (Not entirely ignored: along the lines of [perl
> #126107], the variable gets its default value from the prefix type,
> even if that's inconsistent with the "of" type.) It's also possible to
> give two (clashing) "of" types, if the two "of" clauses are separated
> by another clause:
>
> $ ./perl6 -e 'my Int $a of Str is default("z") of Rat; say "hi"'
> hi
>
> The last "of" type is used as the type constraint. (But again per [perl
> #126107] the default stays even if it's inconsistent with that type.)
>
> Presumably multiple type constraint clauses, however expressed, should
> signal an error. It might be OK to permit multiple type constraints
> specifying exactly the same type, but I don't see a real benefit to that.
> It seems better to forbid multiple specification whether they clash
> or not.
>
> -zefram

Reply via email to