diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index f5c83b0cf991..6a313f35f6d2 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2680,6 +2680,11 @@ BoolResult EnumType::isExplicitlyConvertibleTo(Type const& _convertTo) const return false; } +TypeResult UserDefinedValueType::unaryOperatorResult(Token _operator) const +{ + return _operator == Token::Delete ? TypeProvider::emptyTuple() : nullptr; +} + unsigned EnumType::memberValue(ASTString const& _member) const { unsigned index = 0; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 8d2453d8d503..ce08cce4121f 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -1146,6 +1146,7 @@ class UserDefinedValueType: public Type {} Category category() const override { return Category::UserDefinedValueType; } + TypeResult unaryOperatorResult(Token _operator) const override; Type const& underlyingType() const; UserDefinedValueTypeDefinition const& definition() const { return m_definition; } diff --git a/test/libsolidity/semanticTests/userDefinedValueType/delete.sol b/test/libsolidity/semanticTests/userDefinedValueType/delete.sol new file mode 100644 index 000000000000..b5fb48f6b5d5 --- /dev/null +++ b/test/libsolidity/semanticTests/userDefinedValueType/delete.sol @@ -0,0 +1,43 @@ +type MyUInt256 is uint256; +type MyBytes32 is bytes32; +type MyAddress is address; +type MyBool is bool; + +contract C { + MyUInt256 a = MyUInt256.wrap(255); + + function f() external returns(MyUInt256) { + delete a; + return a; + } + + function g(MyUInt256 b) external returns(MyUInt256) { + delete b; + return b; + } + + function h(MyAddress b) external returns(MyAddress) { + delete b; + return b; + } + + function i(MyBytes32 b) external returns(MyBytes32) { + delete b; + return b; + } + + function j(MyBool b) external returns(MyBool) { + delete b; + return b; + } +} +// ---- +// f() -> 0 +// g(uint256): 255 -> 0 +// g(uint256): 0 -> 0 +// h(address): 0xffffffffffffffffffffffffffffffffffffffff -> 0x0000000000000000000000000000000000000000 +// h(address): 0x0000000000000000000000000000000000000000 -> 0x0000000000000000000000000000000000000000 +// i(bytes32): 0xffffffffffffffffffffffffffffffffffffffff -> 0x0000000000000000000000000000000000000000 +// i(bytes32): 0x0000000000000000000000000000000000000000 -> 0x0000000000000000000000000000000000000000 +// j(bool): true -> false +// j(bool): false -> false \ No newline at end of file