-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Add a new Function Type referring to FunctionDefinition's without calling context and use it to allow selector lookup. #8105
Conversation
6698510
to
dfccce2
Compare
Should have made this a draft... there's a few questions remaining, e.g. how to name those new kinds of function types - and generally, I need feedback about whether this seems like a reasonable direction to go. |
dfccce2
to
ac60395
Compare
0659cb8
to
0925bd4
Compare
@@ -40,10 +40,16 @@ namespace | |||
template <class T, class B> | |||
bool hasEqualNameAndParameters(T const& _a, B const& _b) | |||
{ | |||
auto makeFunctionType = [](auto const& _decl) { | |||
if constexpr (std::is_same_v<std::decay_t<decltype(_decl)>, FunctionDefinition>) |
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.
Fun
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's temporary :-).
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.
As in gone again in a subsequent commit.
libsolidity/ast/Types.cpp
Outdated
string name = "function "; | ||
if (m_kind == Kind::Definition) | ||
{ | ||
// TODO: is this a reasonable way to compute names for these? |
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.
lgtm
...ity/syntaxTests/types/function_types/definition/assign_function_via_contract_name_to_var.sol
Show resolved
Hide resolved
@ekpyron did one pass, looks good at a first glance. There are a lot of changes though, I would like to look at it again. |
Nope, calling However, this is the main reason, why I think it's good to make the type of these things actually a |
(So calling |
Yes that's what I meant |
But yeah, I'm still not entirely sure whether distinguishing these things using a new |
ad66225
to
53ddfa0
Compare
Added some explicit tests for pure functions. |
8c23004
to
79b1903
Compare
if ( | ||
_memberAccess.expression().annotation().type->category() == Type::Category::Function && | ||
member == "selector" | ||
auto const* functionType = dynamic_cast<FunctionType const*>(_memberAccess.expression().annotation().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.
I'm still not used to this. Maybe we could change the style such that the ;
has to be on a line of its own in these cases?
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.
Yeah, I hesitated a bit with this :-). Mainly did it here to avoid blowing up the diff with indentation-only changes below... which is probably not the best reason...
In general I like it, though - if it were up to me alone, I'd e.g. also merge the one a few lines down to
if (
auto const* exprInt = dynamic_cast<Identifier const*>(&expr->expression()));
exprInt && exprInt->name() == "this"
)
Less nesting always seems nicer to me... And less nesting in if
s is likely to avoid brackets arising from otherwise ambiguous else
s... but yeah, I do see the point about potentially forgetting the explicit null check, so not sure...
Not sure I'd still like it, if I had to use a whole line for the ;
, though :-)... Would that really help other than it probably being looked at twice, because it looks weirder :-)?
I can nest here for now, if you prefer and until we decided how to deal with this option in general...
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's fine! I would just like to have this very different kind of if statement stand out a bit more. The fact that you have to read it differently is only apparent towards the end. Would have preferred something like
if <statement> (condition) { ... }
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.
Ready for squsahing!
…atures via contract name.
f9abe49
to
9535c0f
Compare
Squashed it! |
This is probably easiest to review commit by commit.
I first remove the defaulted
_isInternal
bool used to construct function types and replace it by an explicitkind
argument, while reproducing the exact same behaviour as before.Then I add the new
Definition
Kind and make it the default instead. So far if function types were needed without an actual calling context, the kind was "Internal" - now it is "Definition", which I'd say makes more sense.Then finally I added all externally visible functions with kind "definition" as members to the contract TypeType and added appropriate assertions and type checks. Those members themselves for now can only be used for selector lookup with their "selector" members.
This partly fixes #3506 and is related to #7987.
What is missing is proper handling of base contracts, which is what #7987 tried to do, but which will be easier on top of this (as discussed with @Marenz).