Replies: 1 comment 3 replies
-
Related to #162, which I believe is a more robust solution to this problem compared to having an actual |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
According to the documentation about types there is no such type as
void
. Still, you can definevoid
as a return type:When you assing this to a variable, the variable's value and type will be
null
.If you instead define variable's type and try the same:
then you get a runtime error "Trying to assing value type 'Nil' to a variable of type 'int'."
So what is the return type of that function actually?
void
,null
orNil
? This is quite confusing, where did thatNil
come from?I propose that assigning
void
to anything should be an error. I cannot think of any case where assigning return value ofvoid
function to a variable would be useful. But allowing it will cause very likely bugs like this:As
sort
returnsvoid
,arr2
will benull
and I'm pretty sure that's not what the programmer expected.According to the documentation about basic built-in types there actually is a type
null
, but it cannot be used as return type, so is it a type after all? This doesn't work:I propose that
void
andnull
would be distinct types (as they are in e.g. Typescript). Example:I'm not sure if there are any use cases for returning typed
null
s. But ifnull
is an actual type, maybe it should be allowed to be a return type.Beta Was this translation helpful? Give feedback.
All reactions