diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index bfcd2a946..31a4d9871 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1812,7 +1812,6 @@ void TypeChecker::endVisit(BinaryOperation const& _operation) Type const* commonType = leftType; // Either the operator is user-defined or built-in. - // TODO For enums, we have compare operators. Should we disallow overriding them? solAssert(!userDefinedOperator || !builtinResult); if (!builtinResult && !userDefinedOperator) @@ -3848,6 +3847,14 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) } solAssert(_usingFor.typeName()->annotation().type); + + if (_usingFor.typeName()->annotation().type->category() == Type::Category::Enum) + m_errorReporter.typeError( + 9921_error, + _usingFor.location(), + "The \"using\" directive cannot be used to attach functions to the enum type." + ); + Type const* normalizedType = TypeProvider::withLocationIfReference( DataLocation::Storage, _usingFor.typeName()->annotation().type diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol new file mode 100644 index 000000000..4a09bf1a4 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol @@ -0,0 +1,13 @@ +using {add as +} for E; + +enum E { + E1, + E2 +} + +function add(E, E) pure returns (E) { + return E.E1; +} + +// ---- +// TypeError 9921: (0-23): The "using" directive cannot be used to attach functions to the enum type.