I'm looking at the following function which is supposed to return (uint8 id, uint8 nextId). I see that in the body of the function, the return statement is within an "else" statement - see toward the end of the function. Will this function still return id, nextId every time it is run even though the return statement is within an else statement that won't always be executed?
Another way to ask this is do you have to explicitly state within the body of a function that you're expecting it to return something or is it enough to just state it when you define the function?
function setShortRecordIds(address asset, address shorter)
private
returns (uint8 id, uint8 nextId)
{
AppStorage storage s = appStorage();
STypes.ShortRecord storage guard = s.shortRecords[asset][shorter][Constants.HEAD];
STypes.AssetUser storage AssetUser = s.assetUser[asset][shorter];
// Initialize HEAD in case of first short createShortRecord
if (AssetUser.shortRecordId == 0) {
AssetUser.shortRecordId = Constants.SHORT_STARTING_ID;
guard.prevId = Constants.HEAD;
guard.nextId = Constants.HEAD;
}
nextId = guard.nextId;
uint8 canceledId = guard.prevId;
if (canceledId > Constants.HEAD) {
uint8 prevCanceledId = s.shortRecords[asset][shorter][canceledId].prevId;
if (prevCanceledId > Constants.HEAD) {
guard.prevId = prevCanceledId;
} else {
guard.prevId = Constants.HEAD;
}
} else {
id = AssetUser.shortRecordId;
if (id < type(uint8).max) {
AssetUser.shortRecordId += 1;
} else {
// If max id reached, match into max shortRecordId
return (id, nextId);
}
}
if (nextId > Constants.HEAD) {
s.shortRecords[asset][shorter][nextId].prevId = id;
}
guard.nextId = id;
}