-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Warn if override specifier list order differs from inheritance order #8396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Looks good already! |
ekpyron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we warn about this, then I think we should also adjust the order in the suggestion "Function needs to specify overridden contracts [contracts].". Currently that list will ultimately just be alphabetical.
|
that's a good point @ekpyron @chriseth suggested to use for this example, the reversed linearized contracts mismatch the reversed list (filtered by the contracts specified in override) is |
|
You should check in what order |
|
(the question how |
|
Alright, so it was just my intuition that thought this is wrong then. |
Better actually check what |
|
FYI I'm myself not actually sure about requiring any particular order for this at all :-). IIUC we still can't guarantee that |
|
Well, one motivation for this was that people thought the order in |
086c589 to
b71564d
Compare
|
updated to use |
330e866 to
b2b45cc
Compare
ekpyron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions.
| for (size_t i = _item.contract().annotation().linearizedBaseContracts.size() - 1; i > 0; i--) | ||
| { | ||
| auto contract = _item.contract().annotation().linearizedBaseContracts[i]; | ||
| if (missingContracts.count(contract)) | ||
| sortedMissingContracts.emplace_back(contract); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (size_t i = _item.contract().annotation().linearizedBaseContracts.size() - 1; i > 0; i--) | |
| { | |
| auto contract = _item.contract().annotation().linearizedBaseContracts[i]; | |
| if (missingContracts.count(contract)) | |
| sortedMissingContracts.emplace_back(contract); | |
| } | |
| for ( | |
| auto const* contract: _item.contract().annotation().linearizedBaseContracts | | |
| boost::adaptor::filter([](auto const* contract) -> bool { return missingContracts.count(contract); } | |
| ) | |
| sortedMissingContracts.emplace_back(contract); |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestion is no longer reversing the linearized list?
| } | ||
| } | ||
| } | ||
| else if (specifiedContracts.size() > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be much easier, if you did it after you checked that the specified contracts match the expected contracts (and only if they match)?
Then you could just do something like this, couldn't you?
auto overrideIterator = _item.overrides()->overrides().begin();
for (auto const* expected: _item.contract().annotation.linearizedBaseContracts | boost::adaptor::filter([](auto const* base) -> bool { return expectedContracts.count(base); })
if ((overrideIterator++)->annotation().referencedDeclaration != expected)
{
// warn
break;
}
|
Closing this for now as an in-office discussion suggests we're unsure about this feature |
fixes #8373