You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using an if declaration within a function body that expects a return value, the following code compiles with no warnings or errors. This is because the active clause is only examined for a return statement.
Swift requires the code in inactive branches (that don't check language versions) to parse, but not to typecheck. After all, people often use #if to adjust their code to differences elsewhere that can affect the types of declarations.
We can't detect missing {{return}}s in code that hasn't been typechecked because that analysis depends on the types in the code. For instance, if you call a function that returns Never like fatalError(), it's not an error to have no return statement. We wouldn't want to diagnose an error in an inactive branch that won't actually happen when the branch is active.
Therefore, we do not attempt to diagnose missing return statements or other control-flow-sensitive errors (like uses of uninitialized variables) in inactive branches.
Since Swift is working as designed here, I'm going to resolve this bug as "Invalid". (Maybe not the best terminology, but it's the term we have.) If you think I've made a mistake, please reopen this report; otherwise please close it.
Additional Detail from JIRA
md5: 4852cfd70cb40642db091fad21e232e7
Issue Description:
Using an if declaration within a function body that expects a return value, the following code compiles with no warnings or errors. This is because the active clause is only examined for a return statement.
Switching the flag:
You'll get an error missing a return statement.
This should be diagnosed without having to switch the flag.
The text was updated successfully, but these errors were encountered: