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

Mapping arguments and returns #4798

Merged
merged 5 commits into from
Aug 13, 2018
Merged

Mapping arguments and returns #4798

merged 5 commits into from
Aug 13, 2018

Conversation

ekpyron
Copy link
Member

@ekpyron ekpyron commented Aug 10, 2018

Fixes #4670. Fixes #4641.

Related: #4635.

This is a compound PR now, but I don't think it makes too much sense to split it up, since the changes are highly related (I will split, if anyone disagrees, though).

The code changes are minimal, but we have to be sure that the tests (in particular the semantics tests) are sufficient, so let me know if you have test cases you think I should add.

@ekpyron ekpyron self-assigned this Aug 10, 2018
!type(*var)->canLiveOutsideStorage() &&
!(
(_function.visibility() <= FunctionDefinition::Visibility::Internal) &&
type(*var)->category() == Type::Category::Mapping
Copy link
Member Author

Choose a reason for hiding this comment

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

We might want to discuss, whether not living outside storage is a problem for any type in internal functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will create a new issue for removing this check and thinking about canLiveOutsideStorage in general.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #4804.

function f() internal pure returns (mapping(uint=>uint) storage r) { }
}
// ----
// TypeError: (53-82): This variable is of mapping type and might be returned without assignment and could be used uninitialized. Assign the variable (potentially from itself) to fix this error.
Copy link
Member Author

Choose a reason for hiding this comment

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

Since the actual control flow analysis is extensively tested for storage returns, I would say that it's sufficient to only check that mappings are considered at all, instead of duplicating all tests in syntaxTests/controlFlow/storageReturn.

@codecov
Copy link

codecov bot commented Aug 13, 2018

Codecov Report

Merging #4798 into develop will increase coverage by 59.34%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #4798       +/-   ##
===========================================
+ Coverage    28.35%   87.7%   +59.34%     
===========================================
  Files          314     314               
  Lines        30781   31032      +251     
  Branches      3676    3675        -1     
===========================================
+ Hits          8728   27216    +18488     
+ Misses       21380    2566    -18814     
- Partials       673    1250      +577
Flag Coverage Δ
#all 87.7% <100%> (?)
#syntax 28.32% <15.05%> (-0.04%) ⬇️

Changelog.md Outdated
@@ -71,6 +72,7 @@ Language Features:
* General: Support ``pop()`` for storage arrays.
* General: Scoping rules now follow the C99-style.
* General: Allow ``enum``s in interfaces.
* General: Allow ``mapping`` arguments and return values in all internal functions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should clarify that this is only about storage pointers.

@@ -147,7 +150,9 @@ void ControlFlowAnalyzer::checkUnassignedStorageReturnValues(
m_errorReporter.typeError(
returnVal->location(),
ssl,
"This variable is of storage pointer type and might be returned without assignment and "
string("This variable is of ") +
(returnVal->type()->category() == Type::Category::Mapping ? "mapping" : "storage pointer") +
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can both call them storage pointers.

@@ -0,0 +1,6 @@
library L {
function f(mapping(uint => uint) storage) public pure {
Copy link
Contributor

Choose a reason for hiding this comment

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

Syntax highlighting is off here :)

@chriseth chriseth merged commit 3dd31b7 into develop Aug 13, 2018
@ekpyron ekpyron deleted the mappingArgumentsAndReturns branch August 13, 2018 19:50
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.

2 participants