Re: Checking for nil return

[email protected] (Brad Gilbert) Sun, 20 Dec 2020 18:17:59 -0600
Newsgroups perl.perl6.language
Message-ID <CAD2L-T0+7wsm1uX2-KMkdgVwLh3BxVGkqAkBHYAmnRwSZSjtNw@mail.gmail.com>
--0000000000009212e705b6ee6483
Content-Type: text/plain; charset="UTF-8"

Nil is always a valid return value regardless of any check.

This is because it is the base of all failures.

On Sat, Dec 19, 2020, 8:17 PM yary <[email protected]> wrote:

> Is this a known issue, or my misunderstanding?
>
> > subset non-Nil where * !=== Nil;
> (non-Nil)
> > sub out-check($out) returns non-Nil { return $out }
> &out-check
> > out-check(44)
> 44
> > out-check(Nil)
> Nil
>
> ^ Huh, I expected an exception on "out-check(Nil)" saying the return value
> failed the "returns" constraint.
>
> The subtype works as I expect as an the argument check
>
> > sub in-check (non-Nil $in) { $in }
> &in-check
> > in-check(33)
> 33
> > in-check(Nil)
> Constraint type check failed in binding to parameter '$in'; expected
> non-Nil but got Nil (Nil)
>   in sub in-check at <unknown file> line 1
>   in block <unit> at <unknown file> line 1
>
> $ raku --version
> This is Rakudo version 2020.07 built on MoarVM version 2020.07
> implementing Raku 6.d.
>
> Is this my understanding of return type checking that's off, or a known
> issue, or something I should add to an issue tracker?
>
> -y
>

--0000000000009212e705b6ee6483
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Nil is always a valid return value regardless of any chec=
k.<div dir=3D"auto"><br></div><div dir=3D"auto">This is because it is the b=
ase of all failures.</div></div><br><div class=3D"gmail_quote"><div dir=3D"=
ltr" class=3D"gmail_attr">On Sat, Dec 19, 2020, 8:17 PM yary &lt;<a href=3D=
"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"=
><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">Is thi=
s a known issue, or my misunderstanding?</div><div dir=3D"ltr"><br></div><d=
iv dir=3D"ltr">&gt; subset non-Nil where * !=3D=3D=3D Nil;<br></div><div di=
r=3D"ltr">(non-Nil)</div><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"=
>&gt; sub out-check($out) returns non-Nil { return $out }</div><div dir=3D"=
ltr">&amp;out-check</div><div dir=3D"ltr">&gt; out-check(44)</div><div dir=
=3D"ltr">44</div><div dir=3D"ltr">&gt; out-check(Nil)</div><div dir=3D"ltr"=
>Nil</div><br>^ Huh, I expected an exception on &quot;out-check(Nil)&quot; =
saying the return value failed the &quot;returns&quot; constraint.</div><di=
v dir=3D"ltr"><br></div><div>The subtype works as I expect as an the argume=
nt check</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">&gt; sub in-check=
 (non-Nil $in) { $in }</div><div dir=3D"ltr">&amp;in-check</div><div dir=3D=
"ltr">&gt; in-check(33)</div><div dir=3D"ltr">33</div><div dir=3D"ltr">&gt;=
 in-check(Nil)</div><div dir=3D"ltr">Constraint type check failed in bindin=
g to parameter &#39;$in&#39;; expected non-Nil but got Nil (Nil)</div><div =
dir=3D"ltr">=C2=A0 in sub in-check at &lt;unknown file&gt; line 1</div><div=
 dir=3D"ltr">=C2=A0 in block &lt;unit&gt; at &lt;unknown file&gt; line 1</d=
iv><div><br></div></div><div dir=3D"ltr"><div dir=3D"ltr">$ raku --version<=
/div><div dir=3D"ltr">This is Rakudo version 2020.07 built on MoarVM versio=
n 2020.07</div><div dir=3D"ltr">implementing Raku 6.d.</div></div><div dir=
=3D"ltr"><br></div><div>Is this my understanding=C2=A0of return type checki=
ng that&#39;s off, or a known issue, or something I should add to an issue =
tracker?</div><div><br></div><div dir=3D"ltr"><div><div dir=3D"ltr">-y<br><=
/div></div></div></div></div></div></div></div></div>
</blockquote></div>

--0000000000009212e705b6ee6483--