diff options
author | chriseth <chris@ethereum.org> | 2018-05-01 00:19:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-01 00:19:07 +0800 |
commit | 15024154ab5b5211b9567be0b917cb2cbacc87f2 (patch) | |
tree | 425fc47134b99db0eb91a9c5856956a5b822e65e | |
parent | 05248f5a1b6f6122100291f02a6efcb0b5c8f0a0 (diff) | |
parent | 548bf2ff2812cc2fe43f60e915fd62ad9f3cbf87 (diff) | |
download | dexon-solidity-15024154ab5b5211b9567be0b917cb2cbacc87f2.tar.gz dexon-solidity-15024154ab5b5211b9567be0b917cb2cbacc87f2.tar.zst dexon-solidity-15024154ab5b5211b9567be0b917cb2cbacc87f2.zip |
Merge pull request #4018 from ethereum/disable-bytes0
Disable FixedBytesType(0) aka bytes0
-rw-r--r-- | libsolidity/ast/Types.cpp | 13 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 4 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/empty_string_var.sol | 11 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/bytes0.sol | 5 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/bytes256.sol | 5 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/bytes33.sol | 5 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/bytesm.sol | 36 |
7 files changed, 66 insertions, 13 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 60b4d726..11d7160c 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1264,17 +1264,12 @@ bool StringLiteralType::isValidUTF8() const return dev::validateUTF8(m_value); } -shared_ptr<FixedBytesType> FixedBytesType::smallestTypeForLiteral(string const& _literal) -{ - if (_literal.length() <= 32) - return make_shared<FixedBytesType>(_literal.length()); - return shared_ptr<FixedBytesType>(); -} - FixedBytesType::FixedBytesType(int _bytes): m_bytes(_bytes) { - solAssert(m_bytes >= 0 && m_bytes <= 32, - "Invalid byte number for fixed bytes type: " + dev::toString(m_bytes)); + solAssert( + m_bytes > 0 && m_bytes <= 32, + "Invalid byte number for fixed bytes type: " + dev::toString(m_bytes) + ); } bool FixedBytesType::isImplicitlyConvertibleTo(Type const& _convertTo) const diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index b41b2235..a9536657 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -505,10 +505,6 @@ class FixedBytesType: public Type public: virtual Category category() const override { return Category::FixedBytes; } - /// @returns the smallest bytes type for the given literal or an empty pointer - /// if no type fits. - static std::shared_ptr<FixedBytesType> smallestTypeForLiteral(std::string const& _literal); - explicit FixedBytesType(int _bytes); virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; diff --git a/test/libsolidity/syntaxTests/empty_string_var.sol b/test/libsolidity/syntaxTests/empty_string_var.sol new file mode 100644 index 00000000..e9837590 --- /dev/null +++ b/test/libsolidity/syntaxTests/empty_string_var.sol @@ -0,0 +1,11 @@ +contract C { + function f() { + var a = ""; + bytes1 b = bytes1(a); + bytes memory c = bytes(a); + string memory d = string(a); + } +} +// ---- +// Warning: (34-39): Use of the "var" keyword is deprecated. +// TypeError: (61-70): Explicit type conversion not allowed from "string memory" to "bytes1". diff --git a/test/libsolidity/syntaxTests/types/bytes0.sol b/test/libsolidity/syntaxTests/types/bytes0.sol new file mode 100644 index 00000000..7c6d5974 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytes0.sol @@ -0,0 +1,5 @@ +contract C { + bytes0 b0 = 1; +} +// ---- +// DeclarationError: (15-21): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/types/bytes256.sol b/test/libsolidity/syntaxTests/types/bytes256.sol new file mode 100644 index 00000000..22b5408d --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytes256.sol @@ -0,0 +1,5 @@ +contract C { + bytes256 b256 = 1; +} +// ---- +// DeclarationError: (15-23): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/types/bytes33.sol b/test/libsolidity/syntaxTests/types/bytes33.sol new file mode 100644 index 00000000..7edf13d3 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytes33.sol @@ -0,0 +1,5 @@ +contract C { + bytes33 b33 = 1; +} +// ---- +// DeclarationError: (15-22): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/types/bytesm.sol b/test/libsolidity/syntaxTests/types/bytesm.sol new file mode 100644 index 00000000..550760b9 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytesm.sol @@ -0,0 +1,36 @@ +contract C { + byte b = byte(1); + bytes1 b1 = b; + bytes2 b2 = b1; + bytes3 b3 = b2; + bytes4 b4 = b3; + bytes5 b5 = b4; + bytes6 b6 = b5; + bytes7 b7 = b6; + bytes8 b8 = b7; + bytes9 b9 = b8; + bytes10 b10 = b9; + bytes11 b11 = b10; + bytes12 b12 = b11; + bytes13 b13 = b12; + bytes14 b14 = b13; + bytes15 b15 = b14; + bytes16 b16 = b15; + bytes17 b17 = b16; + bytes18 b18 = b17; + bytes19 b19 = b18; + bytes20 b20 = b19; + bytes21 b21 = b20; + bytes22 b22 = b21; + bytes23 b23 = b22; + bytes24 b24 = b23; + bytes25 b25 = b24; + bytes26 b26 = b25; + bytes27 b27 = b26; + bytes28 b28 = b27; + bytes29 b29 = b28; + bytes30 b30 = b29; + bytes31 b31 = b30; + bytes32 b32 = b31; +} +// ---- |