Re: Rationale of return types from subroutines always being nullable?
[email protected] (Elizabeth Mattijsen) Mon, 20 Oct 2025 17:47:51 +0200
| Newsgroups | perl.perl6.users |
|---|---|
| Message-ID | <[email protected]> |
> On 20 Oct 2025, at 17:36, Quanrong via perl6-users <[email protected]> wrote: > Thank you for your reply. You're welcome :-) > My only remaining doubt is, why allow the `:D` smiley at all for return types if it has no effect? Is it used as some kind of statement of intent? That's how I'm using it right now in my own code, to know I don't need to check for Nil when getting a value from that function. But it would be nice to have the compiler help in fulfilling that. Oh, but it *does* serve a purpose, and it *will* fire under the right circumstances! For instance: $ raku -e 'sub a(--> Int:D) { Int }; a' Type check failed for return value; expected Int:D but got Int (Int) in sub a at -e line 1 in block <unit> at -e line 1