Adjust code to review findings

This commit is contained in:
wechman 2022-07-26 15:32:16 +02:00
parent a8bf1f255d
commit c1dc8df9c9
9 changed files with 31 additions and 17 deletions

View File

@ -61,8 +61,6 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
switch (_operation.getOperator())
{
case Token::Conditional:
return true;
case Token::Or:
case Token::And:
{
@ -89,11 +87,13 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
connect(m_currentNode, nextNode);
m_currentNode = nextNode;
}
return false;
}
}
}
return ASTConstVisitor::visit(_operation);
}
bool ControlFlowBuilder::visit(UnaryOperation const& _operation)
{

View File

@ -3853,7 +3853,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
m_errorReporter.typeError(
9921_error,
_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(

View File

@ -403,20 +403,23 @@ FunctionDefinitionResult Type::userDefinedOperator(Token _token, ASTNode const&
);
solAssert(functionType && !functionType->parameterTypes().empty());
solAssert(isImplicitlyConvertibleTo(*functionType->parameterTypes().front()));
if ((_unaryOperation && function.parameterList().parameters().size() == 1) ||
(!_unaryOperation && function.parameterList().parameters().size() == 2))
if (
(_unaryOperation && function.parameterList().parameters().size() == 1) ||
(!_unaryOperation && function.parameterList().parameters().size() == 2)
)
seenFunctions.insert(&function);
}
if (seenFunctions.size() == 1)
return *seenFunctions.begin();
else if (seenFunctions.size() == 0)
return FunctionDefinitionResult::err("A user-defined operator not found.");
else if (!!typeDefinition() && seenFunctions.size() == 0)
return FunctionDefinitionResult::err("Operator has not been user-defined.");
else if (!!typeDefinition())
return FunctionDefinitionResult::err("Multiple user-defined functions provided for this operator.");
else
return FunctionDefinitionResult::err("A user-defined operator not unique.");
return nullptr;
}
MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _scope)
{
MemberList::MemberMap members;

View File

@ -6,7 +6,5 @@ contract C {
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.

View File

@ -17,7 +17,6 @@ contract C {
S storage s;
get() + s;
}
}
// ----

View File

@ -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.

View File

@ -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.

View File

@ -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;
}

View File

@ -14,4 +14,4 @@ function test() {
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.