-
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
Disallow delete on types containing nested mappings. #11843
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1594,11 +1594,18 @@ bool TypeChecker::visit(UnaryOperation const& _operation) | |
requireLValue(_operation.subExpression(), false); | ||
else | ||
_operation.subExpression().accept(*this); | ||
|
||
Type const* subExprType = type(_operation.subExpression()); | ||
Type const* t = type(_operation.subExpression())->unaryOperatorResult(op); | ||
if (!t) | ||
TypeResult result = subExprType->unaryOperatorResult(op); | ||
Type const* t = result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you just remove this and replace every There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember I actually tried that and that there was a problem with that. Something with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes. We're assigning to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my mind assigning to |
||
if (!result) | ||
{ | ||
string description = "Unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->toString(); | ||
string description = "Unary operator " + | ||
string(TokenTraits::toString(op)) + | ||
" cannot be applied to type " + | ||
subExprType->toString() + | ||
(result.message().empty() ? "" : (": " + result.message())); | ||
|
||
if (modifying) | ||
// Cannot just report the error, ignore the unary operator, and continue, | ||
// because the sub-expression was already processed with requireLValue() | ||
|
@@ -2838,6 +2845,15 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) | |
); | ||
|
||
if ( | ||
funType->kind() == FunctionType::Kind::ArrayPop && | ||
exprType->containsNestedMapping() | ||
) | ||
m_errorReporter.typeError( | ||
6298_error, | ||
_memberAccess.location(), | ||
"Storage arrays with nested mappings do not support .pop()." | ||
); | ||
else if ( | ||
funType->kind() == FunctionType::Kind::ArrayPush && | ||
arguments.value().numArguments() != 0 && | ||
exprType->containsNestedMapping() | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ contract C { | |
} | ||
} | ||
// ---- | ||
// TypeError 6298: (109-118): Storage arrays with nested mappings do not support .pop(). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
contract D { | ||
struct Test { | ||
mapping(address => uint) balances; | ||
} | ||
|
||
Test test; | ||
|
||
constructor() | ||
{ | ||
test = Test(); | ||
} | ||
} | ||
// ---- | ||
// TypeError 9214: (102-106): Types in storage containing (nested) mappings cannot be assigned to. | ||
// TypeError 9515: (109-115): Struct containing a (nested) mapping cannot be constructed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
contract D { | ||
struct Test { | ||
mapping(address => uint) balances; | ||
} | ||
|
||
Test test; | ||
|
||
constructor() | ||
{ | ||
delete test; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9767: (102-113): Unary operator delete cannot be applied to type struct D.Test storage ref: Contains a (possibly nested) mapping |
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.
Is this in alphabetic order :-D? I'm honestly not sure :-D. [no need to do anything as far as I'm concerned]
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.
.
befored
, also originally done by vim using:sort
(that's why we had that rebase artefact, it reordered another change, too)