-
Notifications
You must be signed in to change notification settings - Fork 62
Nothing type should affect definite return #4285
Comments
[@gavinking] Interesting. Good idea. I never thought of that. |
[@lucaswerkmeister] The downside with this is that if people do use this (a powerful |
[@gavinking] Well if we did this we could eliminate that warning for the case of an invocation of a function with return type |
[@lucaswerkmeister] Oh, good point. This still discourages stuff like |
[@jvasileff] I think this would be a great improvement, with many uses. But for the common case, I think #3757 would result in much more readable, maintainable, and well documented code. Edit - ok, I see you're not suggesting this be used in expressions. But I don't see how this wouldn't be at least as confusing, as presented in the initial example, as a "buried" throw in an expression. |
[@gavinking] Just pushed an experimental implementation of this, but it's not for 1.2. |
[@lucaswerkmeister] Now that |
For the void type, we ignore the difference to the Anything type. The JS backend does maintain a void flag, but since there is no difference between a function declared void and one returning Anything, we don’t bother with that flag. For the any type… I don’t think we can do any better than just map it to Anything. The only way to mimic the TypeScript behavior of it being assignable to every type would be to map it to Nothing in covariant locations. And that would make #4285 unsound.
@lucaswerkmeister I think at least it should be suppressed for |
[@lucaswerkmeister]
We can reason that since
die
returnsNothing
, it cannot ever return normally (it could throw, terminate the VM / thread, or never return). Therefore,doWork
definitely returns even in theelse
branch, just like if we inserted athrow;
statement there.The typechecker currently doesn’t do this reasoning, though:
I think this reasoning should be possible, since the flow analysis phase happens after the type assignment phase (see also #3997).
And I suppose this could also be applied to definite initialization.
[Migrated from ceylon/ceylon-spec#1179]
The text was updated successfully, but these errors were encountered: