mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
"Operator has not been user-defined." is displayed only is operator can be user-defined
This commit is contained in:
parent
5942912bf1
commit
dcce3fa89b
@ -63,6 +63,7 @@ set(sources
|
||||
ast/CallGraph.cpp
|
||||
ast/CallGraph.h
|
||||
ast/ExperimentalFeatures.h
|
||||
ast/OverridableOperators.h
|
||||
ast/Types.cpp
|
||||
ast/Types.h
|
||||
ast/TypeProvider.cpp
|
||||
|
32
libsolidity/ast/OverridableOperators.h
Normal file
32
libsolidity/ast/OverridableOperators.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <liblangutil/Token.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace solidity::frontend
|
||||
{
|
||||
|
||||
std::vector<langutil::Token> const overridableOperators = {
|
||||
langutil::Token::BitOr,
|
||||
langutil::Token::BitAnd,
|
||||
langutil::Token::BitXor,
|
||||
langutil::Token::Add,
|
||||
langutil::Token::Sub,
|
||||
langutil::Token::Mul,
|
||||
langutil::Token::Div,
|
||||
langutil::Token::Mod,
|
||||
langutil::Token::Equal,
|
||||
langutil::Token::NotEqual,
|
||||
langutil::Token::LessThan,
|
||||
langutil::Token::GreaterThan,
|
||||
langutil::Token::LessThanOrEqual,
|
||||
langutil::Token::GreaterThanOrEqual,
|
||||
langutil::Token::BitNot,
|
||||
langutil::Token::SHL,
|
||||
langutil::Token::SAR,
|
||||
langutil::Token::Exp,
|
||||
langutil::Token::Not
|
||||
};
|
||||
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/ast/TypeProvider.h>
|
||||
#include <libsolidity/ast/OverridableOperators.h>
|
||||
|
||||
#include <libsolidity/analysis/ConstantEvaluator.h>
|
||||
|
||||
@ -387,7 +388,7 @@ vector<UsingForDirective const*> usingForDirectivesForType(Type const& _type, AS
|
||||
|
||||
Result<FunctionDefinition const*> Type::userDefinedOperator(Token _token, ASTNode const& _scope, bool _unaryOperation) const
|
||||
{
|
||||
if (!typeDefinition())
|
||||
if (!typeDefinition() || !util::contains(overridableOperators, _token))
|
||||
return nullptr;
|
||||
|
||||
set<FunctionDefinition const*> matchingDefinitions;
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <libsolidity/parsing/Parser.h>
|
||||
|
||||
#include <libsolidity/ast/OverridableOperators.h>
|
||||
#include <libsolidity/interface/Version.h>
|
||||
#include <libyul/AST.h>
|
||||
#include <libyul/AsmParser.h>
|
||||
@ -980,13 +981,6 @@ ASTPointer<UsingForDirective> Parser::parseUsingDirective()
|
||||
{
|
||||
advance();
|
||||
Token operator_ = m_scanner->currentToken();
|
||||
vector<Token> static const overridableOperators = {
|
||||
Token::BitOr, Token::BitAnd, Token::BitXor,
|
||||
Token::Add, Token::Sub, Token::Mul, Token::Div, Token::Mod,
|
||||
Token::Equal, Token::NotEqual,
|
||||
Token::LessThan, Token::GreaterThan, Token::LessThanOrEqual, Token::GreaterThanOrEqual,
|
||||
Token::BitNot, Token::SHL, Token::SAR, Token::Exp, Token::Not
|
||||
};
|
||||
if (!util::contains(overridableOperators, operator_))
|
||||
{
|
||||
parserError(
|
||||
|
@ -0,0 +1,11 @@
|
||||
type Int is int256;
|
||||
|
||||
function f() pure {
|
||||
Int a = Int.wrap(0);
|
||||
a + a;
|
||||
a >>> a;
|
||||
}
|
||||
|
||||
// ----
|
||||
// TypeError 2271: (70-75): Binary operator + not compatible with types Int and Int. No matching user-defined operator found.
|
||||
// TypeError 2271: (81-88): Binary operator >>> not compatible with types Int and Int.
|
@ -0,0 +1,11 @@
|
||||
type Int is int256;
|
||||
|
||||
function f() pure {
|
||||
Int a = Int.wrap(0);
|
||||
-a;
|
||||
a++;
|
||||
}
|
||||
|
||||
// ----
|
||||
// TypeError 4907: (70-72): Unary operator - cannot be applied to type Int. No matching user-defined operator found.
|
||||
// TypeError 9767: (78-81): Unary operator ++ cannot be applied to type Int.
|
Loading…
Reference in New Issue
Block a user