File test.pm6

unit module test;
subset PosInt of Int is export where * > 0;


File test.p6

use lib '.';
use test;
sub mytest(PosInt $a) { say $a }
mytest(1);     # output: 1
mytest(-1);    # output Constraint type check failed in binding to
parameter '$a'; expected test::PosInt but got Int (-1)

On Wed, Dec 11, 2019 at 7:04 PM JJ Merelo <jjmer...@gmail.com> wrote:

>
>
> El mié., 11 dic. 2019 a las 18:54, JJ Merelo (<jjmer...@gmail.com>)
> escribió:
>
>> Subsets follow pretty much the same rules as every other declared thing.
>> Change subset by "variable" or "class", if the answer is true, it's also
>> true for subsets.
>>
>> By default, the scope of anything (containers, classes, whatever) is
>> lexical to the scope they are in.
>>
>
> Sorry, that's not true. Classes have package scope, not lexical scope, by
> default; that is, they are "our": https://docs.perl6.org/language/classtut
>
> Subsets... well I don't know. I would say they are package scoped by
> default, same as classes.
>
> JJ
>


-- 
Fernando Santagata

Reply via email to