mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow overriding operators for enums
This commit is contained in:
parent
275a43068c
commit
beae1e6263
@ -1812,7 +1812,6 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
|
|||||||
Type const* commonType = leftType;
|
Type const* commonType = leftType;
|
||||||
|
|
||||||
// Either the operator is user-defined or built-in.
|
// Either the operator is user-defined or built-in.
|
||||||
// TODO For enums, we have compare operators. Should we disallow overriding them?
|
|
||||||
solAssert(!userDefinedOperator || !builtinResult);
|
solAssert(!userDefinedOperator || !builtinResult);
|
||||||
|
|
||||||
if (!builtinResult && !userDefinedOperator)
|
if (!builtinResult && !userDefinedOperator)
|
||||||
@ -3848,6 +3847,14 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
solAssert(_usingFor.typeName()->annotation().type);
|
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(
|
Type const* normalizedType = TypeProvider::withLocationIfReference(
|
||||||
DataLocation::Storage,
|
DataLocation::Storage,
|
||||||
_usingFor.typeName()->annotation().type
|
_usingFor.typeName()->annotation().type
|
||||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user