mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adjust code to review findings
This commit is contained in:
parent
a8bf1f255d
commit
c1dc8df9c9
@ -61,8 +61,6 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
|||||||
|
|
||||||
switch (_operation.getOperator())
|
switch (_operation.getOperator())
|
||||||
{
|
{
|
||||||
case Token::Conditional:
|
|
||||||
return true;
|
|
||||||
case Token::Or:
|
case Token::Or:
|
||||||
case Token::And:
|
case Token::And:
|
||||||
{
|
{
|
||||||
@ -89,10 +87,12 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
|||||||
|
|
||||||
connect(m_currentNode, nextNode);
|
connect(m_currentNode, nextNode);
|
||||||
m_currentNode = nextNode;
|
m_currentNode = nextNode;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ASTConstVisitor::visit(_operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ControlFlowBuilder::visit(UnaryOperation const& _operation)
|
bool ControlFlowBuilder::visit(UnaryOperation const& _operation)
|
||||||
|
@ -3853,7 +3853,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
|||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
9921_error,
|
9921_error,
|
||||||
_usingFor.location(),
|
_usingFor.location(),
|
||||||
"The \"using\" directive cannot be used to attach functions to the enum type."
|
"The \"using\" directive cannot be used to attach functions to enum types."
|
||||||
);
|
);
|
||||||
|
|
||||||
Type const* normalizedType = TypeProvider::withLocationIfReference(
|
Type const* normalizedType = TypeProvider::withLocationIfReference(
|
||||||
|
@ -403,20 +403,23 @@ FunctionDefinitionResult Type::userDefinedOperator(Token _token, ASTNode const&
|
|||||||
);
|
);
|
||||||
solAssert(functionType && !functionType->parameterTypes().empty());
|
solAssert(functionType && !functionType->parameterTypes().empty());
|
||||||
solAssert(isImplicitlyConvertibleTo(*functionType->parameterTypes().front()));
|
solAssert(isImplicitlyConvertibleTo(*functionType->parameterTypes().front()));
|
||||||
if ((_unaryOperation && function.parameterList().parameters().size() == 1) ||
|
if (
|
||||||
(!_unaryOperation && function.parameterList().parameters().size() == 2))
|
(_unaryOperation && function.parameterList().parameters().size() == 1) ||
|
||||||
|
(!_unaryOperation && function.parameterList().parameters().size() == 2)
|
||||||
|
)
|
||||||
seenFunctions.insert(&function);
|
seenFunctions.insert(&function);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seenFunctions.size() == 1)
|
if (seenFunctions.size() == 1)
|
||||||
return *seenFunctions.begin();
|
return *seenFunctions.begin();
|
||||||
else if (seenFunctions.size() == 0)
|
else if (!!typeDefinition() && seenFunctions.size() == 0)
|
||||||
return FunctionDefinitionResult::err("A user-defined operator not found.");
|
return FunctionDefinitionResult::err("Operator has not been user-defined.");
|
||||||
|
else if (!!typeDefinition())
|
||||||
|
return FunctionDefinitionResult::err("Multiple user-defined functions provided for this operator.");
|
||||||
else
|
else
|
||||||
return FunctionDefinitionResult::err("A user-defined operator not unique.");
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _scope)
|
MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _scope)
|
||||||
{
|
{
|
||||||
MemberList::MemberMap members;
|
MemberList::MemberMap members;
|
||||||
|
@ -6,7 +6,5 @@ contract C {
|
|||||||
y;
|
y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ---
|
|
||||||
// ----
|
// ----
|
||||||
// TypeError 3464: (137-138): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.
|
|
||||||
// TypeError 3464: (141-142): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.
|
|
||||||
|
@ -17,7 +17,6 @@ contract C {
|
|||||||
S storage s;
|
S storage s;
|
||||||
get() + s;
|
get() + s;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
|
@ -7,4 +7,4 @@ contract test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 2271: (79-85): Operator == not compatible with types struct test.s storage ref and struct test.s storage ref. A user-defined operator not found.
|
// TypeError 2271: (79-85): Operator == not compatible with types struct test.s storage ref and struct test.s storage ref. Operator has not been user-defined.
|
||||||
|
@ -10,4 +10,4 @@ function add(E, E) pure returns (E) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// TypeError 9921: (0-23): The "using" directive cannot be used to attach functions to the enum type.
|
// TypeError 9921: (0-23): The "using" directive cannot be used to attach functions to enum types.
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
struct S { uint v; }
|
||||||
|
|
||||||
|
using {add as +} for S;
|
||||||
|
|
||||||
|
function add(S memory _a, S memory) pure returns (S memory) {
|
||||||
|
return _a;
|
||||||
|
}
|
||||||
|
|
||||||
|
function g() pure returns (S memory) {
|
||||||
|
S memory a = S(0);
|
||||||
|
S memory b = S(1);
|
||||||
|
S memory c = S(2);
|
||||||
|
return a + b + c;
|
||||||
|
}
|
@ -14,4 +14,4 @@ function test() {
|
|||||||
Int.wrap(0) + Int.wrap(1);
|
Int.wrap(0) + Int.wrap(1);
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 2271: (213-238): Operator + not compatible with types Int and Int. A user-defined operator not unique.
|
// TypeError 2271: (213-238): Operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator.
|
||||||
|
Loading…
Reference in New Issue
Block a user