-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Fix overload resolution when conflict is with members of address #2936
Conversation
libsolidity/analysis/TypeChecker.cpp
Outdated
( | ||
// Overloaded functions without declaration (e.g. transfer(), send(), call(), etc.) | ||
it->type->category() == Type::Category::Function && | ||
!dynamic_cast<FunctionType const&>(*it->type).hasDeclaration() |
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.
This looks rather hacky. What about removing the members as part of the type instead of the overload resolution?
I would like var f = x.balance; f();
to work in the same way as x.balance();
. If you need access to the account balance, you can use address(x).balance
.
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.
It is very hacky, should be removed entirely at the breaking release when a contract isn't an child of address.
Do you have a non-hacky solution for keeping the members in non-conflicting cases?
You could try it in |
0192700
to
1ae3ee5
Compare
libsolidity/ast/Types.cpp
Outdated
// Members must overload functions without clash | ||
( | ||
member.type->category() == Type::Category::Function && | ||
dynamic_cast<FunctionType const&>(*member.type).hasEqualArgumentTypes(dynamic_cast<FunctionType const&>(*it->type)) |
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.
This is needed because simply comparing the type takes visibility specifiers into account, which is a can of worms.
@chriseth can you review please? |
contract D { | ||
function f() { | ||
var x = (new C()).balance(); | ||
x; |
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.
This produces "statement does not have an effect" warning. If you want to force "no warnings" I think you should use CHECK_SUCCESS_NO_WARNINGS
or something like that.
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.
Ah, I thought CHECK_SUCCESS_NO_WARNINGS
stands for success and not even warnings. Maybe it should read CHECK_SUCCESS_IGNORE_WARNINGS
.
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.
Sure, that's what it stands for, but I thought that because of the comments above (to avoid pureness warning
) you were aiming for a test without warnings.
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.
So it ignores warnings or doesn't?
Actually I don't mind the warnings myself in this code.
Changelog.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
Features: | |||
* Parser: Better error message for unexpected trailing comma in parameter lists. | |||
* Type Checker: Overload resolution should work with builtins of ``address``. |
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.
I think this is rather about overwriting instead of overloading. What about Fix virtual function lookup when overwriting builtin members of ``address``.
?
libsolidity/ast/Types.cpp
Outdated
@@ -1619,7 +1619,8 @@ string ContractType::canonicalName() const | |||
MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) const | |||
{ | |||
// All address members and all interface functions | |||
MemberList::MemberMap members(IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr)); | |||
MemberList::MemberMap const& addressMembers = IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr); |
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.
This function returns by value, doesn't it?
1ae3ee5
to
e1eaf4e
Compare
libsolidity/ast/Types.cpp
Outdated
for (auto it = addressMembers.begin(); it != addressMembers.end(); ++it) | ||
{ | ||
bool clash = false; | ||
for (auto const member: members) |
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.
Can you extract this into a function?
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.
Or perhaps everything startign from add overloads from address....
?
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.
I was thinking about the same but not sure it helps much. It is quite specific.
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.
It is quite specific, but it will make the containing function shorter.
Basically my thinking is: If you need a comment to describe what a block inside a function does, you should probable move that into its own function. The purpose of the helper function is clear from its name, so you don't need the 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.
Done.
e1eaf4e
to
5270947
Compare
…ance, transfer, etc)
5270947
to
f953b02
Compare
f953b02
to
d5d1a08
Compare
Fixes #2655.