Skip to content
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

Empty tuple components should not be possible #3976

Merged
merged 3 commits into from
Apr 23, 2018
Merged

Conversation

erak
Copy link
Collaborator

@erak erak commented Apr 23, 2018

Fixes #3889

@@ -1418,6 +1418,10 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
components[i]->accept(*this);
types.push_back(type(*components[i]));

if (types[i]->category() == Type::Category::Tuple)
if (dynamic_cast<TupleType const&>(*types[i]).components().empty())
m_errorReporter.fatalTypeError(components[i]->location(), "Type of tuple component cannot be null.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I used the world null in the description of the issue, but this is actually the first place this appears. Perhaps we should say something like "non-empty value"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. "cannot be empty"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think it should only be a warning pre-0.5.0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be up for "cannot be empty". Do you suggest this to be a warning rather than an error? I think we should treat this as an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's again make it a warning pre-050 and an error starting from 050

pragma solidity ^0.4.3;
contract C {
function a() public {
(a(), 7);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test case adds to coverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree :)

Copy link
Contributor

@chriseth chriseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for [f(), f()] where f is a function that returns nothing?

if (types[i]->category() == Type::Category::Tuple)
if (dynamic_cast<TupleType const&>(*types[i]).components().empty())
{
if (!v050)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you swap this? Usually we have if (v050).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

if (!v050)
m_errorReporter.warning(components[i]->location(), "Tuple component cannot be empty.");
else
m_errorReporter.fatalTypeError(components[i]->location(), "Tuple component cannot be empty.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this needs to be fatal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because we cannot assign a proper type.

}
}
// ----
// Warning: (146-149): Tuple component cannot be empty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is wrong, it is not a tuple, it is an array. (the same checks should apply, though, so only the masseg is to be changed).

// ----
// Warning: (146-149): Tuple component cannot be empty.
// Warning: (151-154): Tuple component cannot be empty.
// TypeError: (145-155): Type tuple()[2] memory is not implicitly convertible to expected type tuple(uint256,uint256).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of that, I think we can turn into an error for arrays right away.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean assigning it to a tuple should throw an error even before the components are being checked?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the tuple ast node is used both for tuple expressions and for inline arrays. Empty component should be a warning/error for tuples but an error for arrays.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. Will change it accordingly.

@erak erak force-pushed the emptyTupleComponent branch from f2c93bf to b2ff9bc Compare April 23, 2018 15:11
@chriseth chriseth merged commit e685f9f into develop Apr 23, 2018
@axic axic deleted the emptyTupleComponent branch May 9, 2018 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants