20481, "vasslitvinov", "implicit return types: do unreachable returns matter?", "2022-08-21T00:22:25Z"
What should the following function return?
proc p() type {
if true then
return owned object;
return borrowed object;
}
This is inspired by proc borrowedToOwned() in test/classes/casts/class-type-cast2.chpl
Today's behavior is consistent with the spec: there are two return statements and all return types can be implicitly converted to borrowed object. Even though the second return statement is unreachable, it participates in determining the return type.
Therefore the question in this issue is: is this the behavior that we want?
While there: we want a better error message
When resolving the following function:
proc p() {
if numLocales > 0 then
return 1.2;
else
return "hi";
}
all I get is an error unable to resolve return type pointing at the line with proc p().
I think we should clarify that the compiler was unable to find the best return type and list individual return statements and their types in the error message.