diff options
Diffstat (limited to 'test')
71 files changed, 488 insertions, 152 deletions
diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 145be6e4..6c68100c 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -28,7 +28,7 @@ #pragma warning(push) #pragma warning(disable:4535) // calling _set_se_translator requires /EHa #endif -#include <boost/test/included/unit_test.hpp> +#include <boost/test/unit_test.hpp> #if defined(_MSC_VER) #pragma warning(pop) #endif diff --git a/test/compilationTests/stringutils/strings.sol b/test/compilationTests/stringutils/strings.sol index 390fb5d9..6865664b 100644 --- a/test/compilationTests/stringutils/strings.sol +++ b/test/compilationTests/stringutils/strings.sol @@ -33,13 +33,16 @@ * `s.splitNew('.')` leaves s unmodified, and returns two values * corresponding to the left and right parts of the string. */ + +pragma solidity ^0.4.14; + library strings { struct slice { uint _len; uint _ptr; } - function memcpy(uint dest, uint src, uint len) private { + function memcpy(uint dest, uint src, uint len) private pure { // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { @@ -63,7 +66,7 @@ library strings { * @param self The string to make a slice from. * @return A newly allocated slice containing the entire string. */ - function toSlice(string memory self) internal returns (slice memory) { + function toSlice(string memory self) internal pure returns (slice memory) { uint ptr; assembly { ptr := add(self, 0x20) @@ -76,7 +79,7 @@ library strings { * @param self The value to find the length of. * @return The length of the string, from 0 to 32. */ - function len(bytes32 self) internal returns (uint) { + function len(bytes32 self) internal pure returns (uint) { uint ret; if (self == 0) return 0; @@ -104,12 +107,12 @@ library strings { /* * @dev Returns a slice containing the entire bytes32, interpreted as a - * null-termintaed utf-8 string. + * null-terminated utf-8 string. * @param self The bytes32 value to convert to a slice. * @return A new slice containing the value of the input argument up to the * first null. */ - function toSliceB32(bytes32 self) internal returns (slice memory ret) { + function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { // Allocate space for `self` in memory, copy it there, and point ret at it assembly { let ptr := mload(0x40) @@ -125,7 +128,7 @@ library strings { * @param self The slice to copy. * @return A new slice containing the same data as `self`. */ - function copy(slice memory self) internal returns (slice memory) { + function copy(slice memory self) internal pure returns (slice memory) { return slice(self._len, self._ptr); } @@ -134,7 +137,7 @@ library strings { * @param self The slice to copy. * @return A newly allocated string containing the slice's text. */ - function toString(slice memory self) internal returns (string memory) { + function toString(slice memory self) internal pure returns (string memory) { string memory ret = new string(self._len); uint retptr; assembly { retptr := add(ret, 32) } @@ -151,12 +154,11 @@ library strings { * @param self The slice to operate on. * @return The length of the slice in runes. */ - function len(slice memory self) internal returns (uint) { + function len(slice memory self) internal pure returns (uint l) { // Starting at ptr-31 means the LSB will be the byte we care about uint ptr = self._ptr - 31; uint end = ptr + self._len; - uint len; - for (len = 0; ptr < end; len++) { + for (l = 0; ptr < end; l++) { uint8 b; assembly { b := and(mload(ptr), 0xFF) } if (b < 0x80) { @@ -173,7 +175,6 @@ library strings { ptr += 6; } } - return len; } /* @@ -181,7 +182,7 @@ library strings { * @param self The slice to operate on. * @return True if the slice is empty, False otherwise. */ - function empty(slice memory self) internal returns (bool) { + function empty(slice memory self) internal pure returns (bool) { return self._len == 0; } @@ -194,7 +195,7 @@ library strings { * @param other The second slice to compare. * @return The result of the comparison. */ - function compare(slice memory self, slice memory other) internal returns (int) { + function compare(slice memory self, slice memory other) internal pure returns (int) { uint shortest = self._len; if (other._len < self._len) shortest = other._len; @@ -210,8 +211,11 @@ library strings { } if (a != b) { // Mask out irrelevant bytes and check again - uint mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); - uint diff = (a & mask) - (b & mask); + uint256 mask = uint256(-1); // 0xffff... + if(shortest < 32) { + mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); + } + uint256 diff = (a & mask) - (b & mask); if (diff != 0) return int(diff); } @@ -227,7 +231,7 @@ library strings { * @param self The second slice to compare. * @return True if the slices are equal, false otherwise. */ - function equals(slice memory self, slice memory other) internal returns (bool) { + function equals(slice memory self, slice memory other) internal pure returns (bool) { return compare(self, other) == 0; } @@ -238,7 +242,7 @@ library strings { * @param rune The slice that will contain the first rune. * @return `rune`. */ - function nextRune(slice memory self, slice memory rune) internal returns (slice memory) { + function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) { rune._ptr = self._ptr; if (self._len == 0) { @@ -246,31 +250,31 @@ library strings { return rune; } - uint len; + uint l; uint b; // Load the first byte of the rune into the LSBs of b assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } if (b < 0x80) { - len = 1; + l = 1; } else if(b < 0xE0) { - len = 2; + l = 2; } else if(b < 0xF0) { - len = 3; + l = 3; } else { - len = 4; + l = 4; } // Check for truncated codepoints - if (len > self._len) { + if (l > self._len) { rune._len = self._len; self._ptr += self._len; self._len = 0; return rune; } - self._ptr += len; - self._len -= len; - rune._len = len; + self._ptr += l; + self._len -= l; + rune._len = l; return rune; } @@ -280,7 +284,7 @@ library strings { * @param self The slice to operate on. * @return A slice containing only the first rune from `self`. */ - function nextRune(slice memory self) internal returns (slice memory ret) { + function nextRune(slice memory self) internal pure returns (slice memory ret) { nextRune(self, ret); } @@ -289,40 +293,40 @@ library strings { * @param self The slice to operate on. * @return The number of the first codepoint in the slice. */ - function ord(slice memory self) internal returns (uint ret) { + function ord(slice memory self) internal pure returns (uint ret) { if (self._len == 0) { return 0; } uint word; - uint len; - uint div = 2 ** 248; + uint length; + uint divisor = 2 ** 248; // Load the rune into the MSBs of b assembly { word:= mload(mload(add(self, 32))) } - uint b = word / div; + uint b = word / divisor; if (b < 0x80) { ret = b; - len = 1; + length = 1; } else if(b < 0xE0) { ret = b & 0x1F; - len = 2; + length = 2; } else if(b < 0xF0) { ret = b & 0x0F; - len = 3; + length = 3; } else { ret = b & 0x07; - len = 4; + length = 4; } // Check for truncated codepoints - if (len > self._len) { + if (length > self._len) { return 0; } - for (uint i = 1; i < len; i++) { - div = div / 256; - b = (word / div) & 0xFF; + for (uint i = 1; i < length; i++) { + divisor = divisor / 256; + b = (word / divisor) & 0xFF; if (b & 0xC0 != 0x80) { // Invalid UTF-8 sequence return 0; @@ -338,7 +342,7 @@ library strings { * @param self The slice to hash. * @return The hash of the slice. */ - function keccak(slice memory self) internal returns (bytes32 ret) { + function keccak(slice memory self) internal pure returns (bytes32 ret) { assembly { ret := keccak256(mload(add(self, 32)), mload(self)) } @@ -350,7 +354,7 @@ library strings { * @param needle The slice to search for. * @return True if the slice starts with the provided text, false otherwise. */ - function startsWith(slice memory self, slice memory needle) internal returns (bool) { + function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { if (self._len < needle._len) { return false; } @@ -361,10 +365,10 @@ library strings { bool equal; assembly { - let len := mload(needle) + let length := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } return equal; } @@ -376,7 +380,7 @@ library strings { * @param needle The slice to search for. * @return `self` */ - function beyond(slice memory self, slice memory needle) internal returns (slice memory) { + function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { if (self._len < needle._len) { return self; } @@ -384,10 +388,10 @@ library strings { bool equal = true; if (self._ptr != needle._ptr) { assembly { - let len := mload(needle) + let length := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } } @@ -405,7 +409,7 @@ library strings { * @param needle The slice to search for. * @return True if the slice starts with the provided text, false otherwise. */ - function endsWith(slice memory self, slice memory needle) internal returns (bool) { + function endsWith(slice memory self, slice memory needle) internal pure returns (bool) { if (self._len < needle._len) { return false; } @@ -418,9 +422,9 @@ library strings { bool equal; assembly { - let len := mload(needle) + let length := mload(needle) let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } return equal; @@ -433,7 +437,7 @@ library strings { * @param needle The slice to search for. * @return `self` */ - function until(slice memory self, slice memory needle) internal returns (slice memory) { + function until(slice memory self, slice memory needle) internal pure returns (slice memory) { if (self._len < needle._len) { return self; } @@ -442,9 +446,9 @@ library strings { bool equal = true; if (selfptr != needle._ptr) { assembly { - let len := mload(needle) + let length := mload(needle) let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } } @@ -457,31 +461,33 @@ library strings { // Returns the memory address of the first byte of the first occurrence of // `needle` in `self`, or the first byte after `self` if not found. - function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private returns (uint) { - uint ptr; + function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { + uint ptr = selfptr; uint idx; if (needlelen <= selflen) { if (needlelen <= 32) { - // Optimized assembly for 68 gas per byte on short strings - assembly { - let mask := not(sub(exp(2, mul(8, sub(32, needlelen))), 1)) - let needledata := and(mload(needleptr), mask) - let end := add(selfptr, sub(selflen, needlelen)) - ptr := selfptr - loop: - jumpi(exit, eq(and(mload(ptr), mask), needledata)) - ptr := add(ptr, 1) - jumpi(loop, lt(sub(ptr, 1), end)) - ptr := add(selfptr, selflen) - exit: + bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + + bytes32 needledata; + assembly { needledata := and(mload(needleptr), mask) } + + uint end = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly { ptrdata := and(mload(ptr), mask) } + + while (ptrdata != needledata) { + if (ptr >= end) + return selfptr + selflen; + ptr++; + assembly { ptrdata := and(mload(ptr), mask) } } return ptr; } else { // For long needles, use hashing bytes32 hash; assembly { hash := keccak256(needleptr, needlelen) } - ptr = selfptr; + for (idx = 0; idx <= selflen - needlelen; idx++) { bytes32 testHash; assembly { testHash := keccak256(ptr, needlelen) } @@ -496,27 +502,27 @@ library strings { // Returns the memory address of the first byte after the last occurrence of // `needle` in `self`, or the address of `self` if not found. - function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private returns (uint) { + function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { uint ptr; if (needlelen <= selflen) { if (needlelen <= 32) { - // Optimized assembly for 69 gas per byte on short strings - assembly { - let mask := not(sub(exp(2, mul(8, sub(32, needlelen))), 1)) - let needledata := and(mload(needleptr), mask) - ptr := add(selfptr, sub(selflen, needlelen)) - loop: - jumpi(ret, eq(and(mload(ptr), mask), needledata)) - ptr := sub(ptr, 1) - jumpi(loop, gt(add(ptr, 1), selfptr)) - ptr := selfptr - jump(exit) - ret: - ptr := add(ptr, needlelen) - exit: + bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + + bytes32 needledata; + assembly { needledata := and(mload(needleptr), mask) } + + ptr = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly { ptrdata := and(mload(ptr), mask) } + + while (ptrdata != needledata) { + if (ptr <= selfptr) + return selfptr; + ptr--; + assembly { ptrdata := and(mload(ptr), mask) } } - return ptr; + return ptr + needlelen; } else { // For long needles, use hashing bytes32 hash; @@ -542,7 +548,7 @@ library strings { * @param needle The text to search for. * @return `self`. */ - function find(slice memory self, slice memory needle) internal returns (slice memory) { + function find(slice memory self, slice memory needle) internal pure returns (slice memory) { uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); self._len -= ptr - self._ptr; self._ptr = ptr; @@ -557,7 +563,7 @@ library strings { * @param needle The text to search for. * @return `self`. */ - function rfind(slice memory self, slice memory needle) internal returns (slice memory) { + function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) { uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); self._len = ptr - self._ptr; return self; @@ -573,7 +579,7 @@ library strings { * @param token An output parameter to which the first token is written. * @return `token`. */ - function split(slice memory self, slice memory needle, slice memory token) internal returns (slice memory) { + function split(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); token._ptr = self._ptr; token._len = ptr - self._ptr; @@ -596,7 +602,7 @@ library strings { * @param needle The text to search for in `self`. * @return The part of `self` up to the first occurrence of `delim`. */ - function split(slice memory self, slice memory needle) internal returns (slice memory token) { + function split(slice memory self, slice memory needle) internal pure returns (slice memory token) { split(self, needle, token); } @@ -610,7 +616,7 @@ library strings { * @param token An output parameter to which the first token is written. * @return `token`. */ - function rsplit(slice memory self, slice memory needle, slice memory token) internal returns (slice memory) { + function rsplit(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); token._ptr = ptr; token._len = self._len - (ptr - self._ptr); @@ -632,7 +638,7 @@ library strings { * @param needle The text to search for in `self`. * @return The part of `self` after the last occurrence of `delim`. */ - function rsplit(slice memory self, slice memory needle) internal returns (slice memory token) { + function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) { rsplit(self, needle, token); } @@ -642,10 +648,10 @@ library strings { * @param needle The text to search for in `self`. * @return The number of occurrences of `needle` found in `self`. */ - function count(slice memory self, slice memory needle) internal returns (uint count) { + function count(slice memory self, slice memory needle) internal pure returns (uint cnt) { uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; while (ptr <= self._ptr + self._len) { - count++; + cnt++; ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; } } @@ -656,7 +662,7 @@ library strings { * @param needle The text to search for in `self`. * @return True if `needle` is found in `self`, false otherwise. */ - function contains(slice memory self, slice memory needle) internal returns (bool) { + function contains(slice memory self, slice memory needle) internal pure returns (bool) { return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; } @@ -667,7 +673,7 @@ library strings { * @param other The second slice to concatenate. * @return The concatenation of the two strings. */ - function concat(slice memory self, slice memory other) internal returns (string memory) { + function concat(slice memory self, slice memory other) internal pure returns (string memory) { string memory ret = new string(self._len + other._len); uint retptr; assembly { retptr := add(ret, 32) } @@ -684,15 +690,15 @@ library strings { * @return A newly allocated string containing all the slices in `parts`, * joined with `self`. */ - function join(slice memory self, slice[] memory parts) internal returns (string memory) { + function join(slice memory self, slice[] memory parts) internal pure returns (string memory) { if (parts.length == 0) return ""; - uint len = self._len * (parts.length - 1); + uint length = self._len * (parts.length - 1); for(uint i = 0; i < parts.length; i++) - len += parts[i]._len; + length += parts[i]._len; - string memory ret = new string(len); + string memory ret = new string(length); uint retptr; assembly { retptr := add(ret, 32) } diff --git a/test/contracts/LLL_ENS.cpp b/test/contracts/LLL_ENS.cpp index 3461c577..cfd6970c 100644 --- a/test/contracts/LLL_ENS.cpp +++ b/test/contracts/LLL_ENS.cpp @@ -28,7 +28,7 @@ #define ACCOUNT(n) h256(account(n), h256::AlignRight) using namespace std; -using namespace dev::eth; +using namespace dev::lll; namespace dev { diff --git a/test/contracts/LLL_ERC20.cpp b/test/contracts/LLL_ERC20.cpp index 89d1c4f0..6c6762dd 100644 --- a/test/contracts/LLL_ERC20.cpp +++ b/test/contracts/LLL_ERC20.cpp @@ -33,7 +33,7 @@ #define SUCCESS encodeArgs(1) using namespace std; -using namespace dev::eth; +using namespace dev::lll; namespace dev { diff --git a/test/liblll/Compiler.cpp b/test/liblll/Compiler.cpp index ebdea185..1e6f6d87 100644 --- a/test/liblll/Compiler.cpp +++ b/test/liblll/Compiler.cpp @@ -46,7 +46,7 @@ namespace bool successCompile(string const& _sourceCode) { vector<string> errors; - bytes bytecode = eth::compileLLL(_sourceCode, dev::test::Options::get().evmVersion(), false, &errors); + bytes bytecode = lll::compileLLL(_sourceCode, dev::test::Options::get().evmVersion(), false, &errors); if (!errors.empty()) return false; if (bytecode.empty()) @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_functional) for (size_t i = 0; i < opcodes_bytecode.size(); i++) { vector<string> errors; - bytes code = eth::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors); + bytes code = lll::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors); BOOST_REQUIRE_MESSAGE(errors.empty(), opcodes_lll[i]); @@ -646,7 +646,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_asm) for (size_t i = 0; i < opcodes_bytecode.size(); i++) { vector<string> errors; - bytes code = eth::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors); + bytes code = lll::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors); BOOST_REQUIRE_MESSAGE(errors.empty(), opcodes_lll[i]); diff --git a/test/liblll/ExecutionFramework.h b/test/liblll/ExecutionFramework.h index ae5cd988..7c1ce670 100644 --- a/test/liblll/ExecutionFramework.h +++ b/test/liblll/ExecutionFramework.h @@ -56,7 +56,7 @@ public: BOOST_REQUIRE(_libraryAddresses.empty()); std::vector<std::string> errors; - bytes bytecode = eth::compileLLL(_sourceCode, dev::test::Options::get().evmVersion(), m_optimize, &errors); + bytes bytecode = lll::compileLLL(_sourceCode, dev::test::Options::get().evmVersion(), m_optimize, &errors); if (!errors.empty()) { for (auto const& error: errors) diff --git a/test/liblll/Parser.cpp b/test/liblll/Parser.cpp index fc977b81..d343aab1 100644 --- a/test/liblll/Parser.cpp +++ b/test/liblll/Parser.cpp @@ -39,13 +39,13 @@ namespace bool successParse(std::string const& _source) { - std::string ret = eth::parseLLL(_source); + std::string ret = lll::parseLLL(_source); return ret.size() != 0; } std::string parse(std::string const& _source) { - return eth::parseLLL(_source); + return lll::parseLLL(_source); } } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index be590557..223250fa 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1534,7 +1534,7 @@ BOOST_AUTO_TEST_CASE(struct_reference) } function set() public { data.z = 2; - mapping(uint8 => s2) map = data.recursive; + mapping(uint8 => s2) storage map = data.recursive; s2 storage inner = map[0]; inner.z = 3; inner.recursive[0].z = inner.recursive[1].z + 1; diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 3e2dce26..119f80d1 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -74,9 +74,9 @@ public: unsigned const _optimizeRuns = 200 ) { - m_nonOptimizedBytecode = compileAndRunWithOptimizer(_sourceCode, _value, _contractName, false, _optimizeRuns); + m_nonOptimizedBytecode = compileAndRunWithOptimizer("pragma solidity >=0.0;\n" + _sourceCode, _value, _contractName, false, _optimizeRuns); m_nonOptimizedContract = m_contractAddress; - m_optimizedBytecode = compileAndRunWithOptimizer(_sourceCode, _value, _contractName, true, _optimizeRuns); + m_optimizedBytecode = compileAndRunWithOptimizer("pragma solidity >=0.0;\n" + _sourceCode, _value, _contractName, true, _optimizeRuns); size_t nonOptimizedSize = numInstructions(m_nonOptimizedBytecode); size_t optimizedSize = numInstructions(m_optimizedBytecode); BOOST_CHECK_MESSAGE( @@ -441,8 +441,6 @@ BOOST_AUTO_TEST_CASE(constant_optimization_early_exit) // This tests that the constant optimizer does not try to find the best representation // indefinitely but instead stops after some number of iterations. char const* sourceCode = R"( - pragma solidity ^0.4.0; - contract HexEncoding { function hexEncodeTest(address addr) public returns (bytes32 ret) { uint x = uint(addr) / 2**32; diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index f455c5eb..42e1b18e 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -64,6 +64,14 @@ BOOST_AUTO_TEST_CASE(string_escapes) BOOST_CHECK_EQUAL(scanner.currentLiteral(), "aa"); } +BOOST_AUTO_TEST_CASE(string_escapes_all) +{ + Scanner scanner(CharStream(" { \"a\\x61\\b\\f\\n\\r\\t\\v\"")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); + BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "aa\b\f\n\r\t\v"); +} + BOOST_AUTO_TEST_CASE(string_escapes_with_zero) { Scanner scanner(CharStream(" { \"a\\x61\\x00abc\"")); @@ -199,7 +207,7 @@ BOOST_AUTO_TEST_CASE(locations) BOOST_AUTO_TEST_CASE(ambiguities) { // test scanning of some operators which need look-ahead - Scanner scanner(CharStream("<=""<""+ +=a++ =>""<<")); + Scanner scanner(CharStream("<=" "<" "+ +=a++ =>" "<<" ">>" " >>=" ">>>" ">>>=" " >>>>>=><<=")); BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LessThanOrEqual); BOOST_CHECK_EQUAL(scanner.next(), Token::LessThan); BOOST_CHECK_EQUAL(scanner.next(), Token::Add); @@ -208,6 +216,15 @@ BOOST_AUTO_TEST_CASE(ambiguities) BOOST_CHECK_EQUAL(scanner.next(), Token::Inc); BOOST_CHECK_EQUAL(scanner.next(), Token::Arrow); BOOST_CHECK_EQUAL(scanner.next(), Token::SHL); + BOOST_CHECK_EQUAL(scanner.next(), Token::SAR); + BOOST_CHECK_EQUAL(scanner.next(), Token::AssignSar); + BOOST_CHECK_EQUAL(scanner.next(), Token::SHR); + BOOST_CHECK_EQUAL(scanner.next(), Token::AssignShr); + // the last "monster" token combination + BOOST_CHECK_EQUAL(scanner.next(), Token::SHR); + BOOST_CHECK_EQUAL(scanner.next(), Token::AssignSar); + BOOST_CHECK_EQUAL(scanner.next(), Token::GreaterThan); + BOOST_CHECK_EQUAL(scanner.next(), Token::AssignShl); } BOOST_AUTO_TEST_CASE(documentation_comments_parsed_begin) diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_calldata.sol b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_calldata.sol new file mode 100644 index 00000000..d3ac2acc --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_calldata.sol @@ -0,0 +1,3 @@ +library test { + function f(bytes calldata) external; +} diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_memory.sol b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_memory.sol new file mode 100644 index 00000000..6fa0a152 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_memory.sol @@ -0,0 +1,5 @@ +library test { + function f(bytes memory) external; +} +// ---- +// TypeError: (30-35): Location has to be calldata or storage for external library functions (remove the "memory" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_storage.sol b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_storage.sol new file mode 100644 index 00000000..2ee68ef9 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_storage.sol @@ -0,0 +1,3 @@ +library test { + function f(bytes storage) external; +} diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_calldata.sol b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_calldata.sol new file mode 100644 index 00000000..868c5c30 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_calldata.sol @@ -0,0 +1,5 @@ +library test { + function f(bytes calldata) internal pure {} +} +// ---- +// TypeError: (30-35): Variable cannot be declared as "calldata" (remove the "calldata" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_memory.sol b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_memory.sol new file mode 100644 index 00000000..78a30f5b --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_memory.sol @@ -0,0 +1,3 @@ +library test { + function f(bytes memory) internal pure {} +} diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_storage.sol b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_storage.sol new file mode 100644 index 00000000..b51f148b --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_storage.sol @@ -0,0 +1,3 @@ +library test { + function f(bytes storage) internal pure {} +} diff --git a/test/libsolidity/syntaxTests/emit_empty.sol b/test/libsolidity/syntaxTests/emit_empty.sol new file mode 100644 index 00000000..819d88fe --- /dev/null +++ b/test/libsolidity/syntaxTests/emit_empty.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + emit; + } +} +// ---- +// ParserError: (45-46): Expected event name or path. diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol index 6549eb48..51f0b10d 100644 --- a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol +++ b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol @@ -3,5 +3,5 @@ contract C { constructor() public x; } // ---- -// Warning: (83-106): Modifiers of functions without implementation are ignored. +// SyntaxError: (83-106): Functions without implementation cannot have modifiers. // DeclarationError: (104-105): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/indexing/array_out_of_bounds_index.sol b/test/libsolidity/syntaxTests/indexing/array_out_of_bounds_index.sol new file mode 100644 index 00000000..b0079857 --- /dev/null +++ b/test/libsolidity/syntaxTests/indexing/array_out_of_bounds_index.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + bytes[32] memory a; + a[64]; + } +} +// ---- +// TypeError: (65-70): Out of bounds array access. diff --git a/test/libsolidity/syntaxTests/indexing/array_without_index.sol b/test/libsolidity/syntaxTests/indexing/array_without_index.sol new file mode 100644 index 00000000..6b1c2778 --- /dev/null +++ b/test/libsolidity/syntaxTests/indexing/array_without_index.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + bytes memory a; + a[]; + } +} +// ---- +// TypeError: (61-64): Index expression cannot be omitted. diff --git a/test/libsolidity/syntaxTests/indexing/fixedbytes_out_of_bounds_index.sol b/test/libsolidity/syntaxTests/indexing/fixedbytes_out_of_bounds_index.sol new file mode 100644 index 00000000..8264a8b2 --- /dev/null +++ b/test/libsolidity/syntaxTests/indexing/fixedbytes_out_of_bounds_index.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + bytes32 b; + b[64]; + } +} +// ---- +// TypeError: (56-61): Out of bounds array access. diff --git a/test/libsolidity/syntaxTests/indexing/fixedbytes_without_index.sol b/test/libsolidity/syntaxTests/indexing/fixedbytes_without_index.sol new file mode 100644 index 00000000..979ac8a7 --- /dev/null +++ b/test/libsolidity/syntaxTests/indexing/fixedbytes_without_index.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + bytes32 b; + b[]; + } +} +// ---- +// TypeError: (56-59): Index expression cannot be omitted. diff --git a/test/libsolidity/syntaxTests/indexing/function_type.sol b/test/libsolidity/syntaxTests/indexing/function_type.sol new file mode 100644 index 00000000..6c6c06a9 --- /dev/null +++ b/test/libsolidity/syntaxTests/indexing/function_type.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + f[0]; + } +} +// ---- +// TypeError: (41-42): Indexed expression has to be a type, mapping or array (is function ()) diff --git a/test/libsolidity/syntaxTests/indexing/function_type_without_index.sol b/test/libsolidity/syntaxTests/indexing/function_type_without_index.sol new file mode 100644 index 00000000..bf511bc9 --- /dev/null +++ b/test/libsolidity/syntaxTests/indexing/function_type_without_index.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + f[]; + } +} +// ---- +// TypeError: (41-42): Indexed expression has to be a type, mapping or array (is function ()) diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_contract.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_contract.sol new file mode 100644 index 00000000..a87a3e66 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_contract.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + let x := C + } + } +} +// ---- +// TypeError: (72-73): Expected a library. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_functiontype.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_functiontype.sol new file mode 100644 index 00000000..ecda3e99 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_functiontype.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure { + assembly { + let x := f + } + } +} diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_library.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_library.sol new file mode 100644 index 00000000..3c551c18 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_library.sol @@ -0,0 +1,10 @@ +library L { +} + +contract C { + function f() public pure { + assembly { + let x := L + } + } +} diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_super.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_super.sol new file mode 100644 index 00000000..bd5562d5 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_from_super.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + let x := super + } + } +} +// ---- +// DeclarationError: (72-77): Identifier not found. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_special.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_special.sol new file mode 100644 index 00000000..db28e507 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_special.sol @@ -0,0 +1,13 @@ +contract C { + function f() public { + assembly { + super := 1 + f := 1 + C := 1 + } + } +} +// ---- +// TypeError: (58-63): Only local variables can be assigned to in inline assembly. +// TypeError: (75-76): Only local variables can be assigned to in inline assembly. +// TypeError: (88-89): Only local variables can be assigned to in inline assembly. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/function_call_invalid_argument_count.sol b/test/libsolidity/syntaxTests/inlineAssembly/function_call_invalid_argument_count.sol new file mode 100644 index 00000000..cbea8991 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/function_call_invalid_argument_count.sol @@ -0,0 +1,16 @@ +contract C { + function f() public pure { + assembly { + function f(a) {} + + f() + f(1) + f(1, 2) + } + } +} +// ---- +// TypeError: (87-88): Expected 1 arguments but got 0. +// Warning: (87-90): Top-level expressions are not supposed to return values (this expression returns -1 values). Use ``pop()`` or assign them. +// TypeError: (108-109): Expected 1 arguments but got 2. +// Warning: (108-115): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/function_call_not_found.sol b/test/libsolidity/syntaxTests/inlineAssembly/function_call_not_found.sol new file mode 100644 index 00000000..57534bd6 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/function_call_not_found.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + k() + } + } +} +// ---- +// DeclarationError: (63-64): Function not found. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/function_call_to_label.sol b/test/libsolidity/syntaxTests/inlineAssembly/function_call_to_label.sol new file mode 100644 index 00000000..5de492e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/function_call_to_label.sol @@ -0,0 +1,13 @@ +contract C { + function f() public pure { + assembly { + l: + + l() + } + } +} +// ---- +// Warning: (63-64): The use of labels is deprecated. Please use "if", "switch", "for" or function calls instead. +// Warning: (63-64): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. +// TypeError: (73-74): Attempt to call label instead of function. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/function_call_to_variable.sol b/test/libsolidity/syntaxTests/inlineAssembly/function_call_to_variable.sol new file mode 100644 index 00000000..c0071855 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/function_call_to_variable.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure { + assembly { + let x := 1 + + x() + } + } +} +// ---- +// TypeError: (81-82): Attempt to call variable instead of function. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/function_without_call.sol b/test/libsolidity/syntaxTests/inlineAssembly/function_without_call.sol new file mode 100644 index 00000000..8557e2fa --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/function_without_call.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure { + assembly { + function k() {} + + k + } + } +} +// ---- +// TypeError: (86-87): Function k used without being called. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_assignment.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_assignment.sol new file mode 100644 index 00000000..d5c8eaf5 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_assignment.sol @@ -0,0 +1,13 @@ +contract C { + uint[] x; + function() external { + uint[] storage y = x; + assembly { + y_slot := 1 + y_offset := 2 + } + } +} +// ---- +// TypeError: (115-121): Storage variables cannot be assigned to. +// TypeError: (139-147): Storage variables cannot be assigned to. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_memory.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_memory.sol new file mode 100644 index 00000000..4025e11c --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_memory.sol @@ -0,0 +1,13 @@ +contract C { + uint[] x; + function() external { + uint[] memory y = x; + assembly { + pop(y_slot) + pop(y_offset) + } + } +} +// ---- +// TypeError: (118-124): The suffixes _offset and _slot can only be used on storage variables. +// TypeError: (142-150): The suffixes _offset and _slot can only be used on storage variables. diff --git a/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol b/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol index e18c5cf9..2e86fcc1 100644 --- a/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol +++ b/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol @@ -9,5 +9,5 @@ contract C function bar() public only_owner; } // ---- -// Warning: (203-236): Modifiers of functions without implementation are ignored. -// Warning: (241-274): Modifiers of functions without implementation are ignored. +// SyntaxError: (203-236): Functions without implementation cannot have modifiers. +// SyntaxError: (241-274): Functions without implementation cannot have modifiers. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol index 8bf45c3f..27b1ea96 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol @@ -4,9 +4,9 @@ contract test { } str data; function fun() public { - mapping(uint=>uint) a = data.map; + mapping(uint=>uint) storage a = data.map; data.map = a; } } // ---- -// TypeError: (164-176): Mappings cannot be assigned to. +// TypeError: (172-184): Mappings cannot be assigned to. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol index 27651d63..b15666c0 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol @@ -1,9 +1,9 @@ contract C { mapping(uint => uint) x; function f() public returns (bool ret) { - mapping(uint => uint) y = x; + mapping(uint => uint) storage y = x; return x == y; } } // ---- -// TypeError: (139-145): Operator == not compatible with types mapping(uint256 => uint256) and mapping(uint256 => uint256) +// TypeError: (147-153): Operator == not compatible with types mapping(uint256 => uint256) and mapping(uint256 => uint256) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol index 6b25cdfe..0547ace1 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol @@ -1,8 +1,8 @@ contract C { function f() public { - mapping(uint => uint) x; + mapping(uint => uint) storage x; x; } } // ---- -// TypeError: (47-70): Uninitialized mapping. Mappings cannot be created dynamically, you have to assign them from a state variable. +// TypeError: (47-78): Uninitialized mapping. Mappings cannot be created dynamically, you have to assign them from a state variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol index f0bb557b..e45e09de 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol @@ -1,7 +1,7 @@ contract C { function f(uint size) public { - mapping(uint => uint) x = new mapping(uint => uint)[](4); + mapping(uint => uint) storage x = new mapping(uint => uint)[](4); } } // ---- -// TypeError: (86-109): Type cannot live outside storage. +// TypeError: (94-117): Type cannot live outside storage. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol index 41e72d60..e9ab08ba 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol @@ -71,7 +71,7 @@ contract C { (uint n, uint o) = true ? (1, 2) : (3, 4); (n, o) = (o, n); // Avoid unused var warning // mapping - mapping(uint8 => uint8) p = true ? table1 : table2; + mapping(uint8 => uint8) storage p = true ? table1 : table2; p[0] = 0; // Avoid unused var warning // typetype uint32 q = true ? uint32(1) : uint32(2); diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword.sol deleted file mode 100644 index 1b6bbae7..00000000 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword.sol +++ /dev/null @@ -1,11 +0,0 @@ -contract test { - function f() public { - uintM something = 3; - intM should = 4; - bytesM fail = "now"; - } -} -// ---- -// DeclarationError: (50-55): Identifier not found or not unique. -// DeclarationError: (79-83): Identifier not found or not unique. -// DeclarationError: (104-110): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_1.sol new file mode 100644 index 00000000..0d0a0797 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_1.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + uintM something = 3; + } +} +// ---- +// DeclarationError: (50-55): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_2.sol new file mode 100644 index 00000000..b9590a8c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_2.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + intM should = 4; + } +} +// ---- +// DeclarationError: (50-54): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_3.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_3.sol new file mode 100644 index 00000000..85d4c25b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword_3.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + bytesM fail = "now"; + } +} +// ---- +// DeclarationError: (50-56): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/570_function_type_undeclared_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/570_function_type_undeclared_type.sol new file mode 100644 index 00000000..962f4fe4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/570_function_type_undeclared_type.sol @@ -0,0 +1,5 @@ +contract C { + function a(function(Nested)) external pure {} +} +// ---- +// DeclarationError: (37-43): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/571_function_type_undeclared_type_external.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/571_function_type_undeclared_type_external.sol new file mode 100644 index 00000000..735af9e9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/571_function_type_undeclared_type_external.sol @@ -0,0 +1,5 @@ +contract C { + function a(function(Nested) external) external pure {} +} +// ---- +// DeclarationError: (37-43): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/572_function_type_undeclared_type_multi_nested.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/572_function_type_undeclared_type_multi_nested.sol new file mode 100644 index 00000000..ffb467cd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/572_function_type_undeclared_type_multi_nested.sol @@ -0,0 +1,5 @@ +contract C { + function a(function(function(function(Nested)))) external pure {} +} +// ---- +// DeclarationError: (55-61): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/parsing/assembly_evmasm_type.sol b/test/libsolidity/syntaxTests/parsing/assembly_evmasm_type.sol new file mode 100644 index 00000000..28a07e63 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/assembly_evmasm_type.sol @@ -0,0 +1,5 @@ +contract C { + function f() public pure { + assembly "evmasm" {} + } +} diff --git a/test/libsolidity/syntaxTests/parsing/assembly_invalid_type.sol b/test/libsolidity/syntaxTests/parsing/assembly_invalid_type.sol new file mode 100644 index 00000000..c2d39279 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/assembly_invalid_type.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure { + assembly "failasm" {} + } +} +// ---- +// ParserError: (55-64): Only "evmasm" supported. diff --git a/test/libsolidity/syntaxTests/parsing/import_complex.sol b/test/libsolidity/syntaxTests/parsing/import_complex.sol new file mode 100644 index 00000000..8bbb0a88 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/import_complex.sol @@ -0,0 +1,3 @@ +import {hello, world} from "hello"; +// ---- +// ParserError: (0-35): Source "hello" not found: File not supplied initially. diff --git a/test/libsolidity/syntaxTests/parsing/import_complex_invalid_from.sol b/test/libsolidity/syntaxTests/parsing/import_complex_invalid_from.sol new file mode 100644 index 00000000..c4667606 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/import_complex_invalid_from.sol @@ -0,0 +1,3 @@ +import {hello, world} from function; +// ---- +// ParserError: (27-35): Expected import path. diff --git a/test/libsolidity/syntaxTests/parsing/import_complex_without_from.sol b/test/libsolidity/syntaxTests/parsing/import_complex_without_from.sol new file mode 100644 index 00000000..961acb22 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/import_complex_without_from.sol @@ -0,0 +1,3 @@ +import {hello, world}; +// ---- +// ParserError: (21-22): Expected "from". diff --git a/test/libsolidity/syntaxTests/parsing/import_invalid_token.sol b/test/libsolidity/syntaxTests/parsing/import_invalid_token.sol new file mode 100644 index 00000000..df837e28 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/import_invalid_token.sol @@ -0,0 +1,3 @@ +import function; +// ---- +// ParserError: (7-15): Expected string literal (path), "*" or alias list. diff --git a/test/libsolidity/syntaxTests/parsing/import_simple.sol b/test/libsolidity/syntaxTests/parsing/import_simple.sol new file mode 100644 index 00000000..5d61a8bb --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/import_simple.sol @@ -0,0 +1,3 @@ +import "hello"; +// ---- +// ParserError: (0-15): Source "hello" not found: File not supplied initially. diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals_multi.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals_multi.sol new file mode 100644 index 00000000..d53208ef --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals_multi.sol @@ -0,0 +1,12 @@ +contract Foo { + uint[] m_x; + function f() public view { + uint[] storage memory x = m_x; + uint[] memory storage calldata y; + x; y; + } +} +// ---- +// ParserError: (85-91): Location already specified. +// ParserError: (123-130): Location already specified. +// ParserError: (131-139): Location already specified. diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params_multi.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params_multi.sol new file mode 100644 index 00000000..c6155c09 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params_multi.sol @@ -0,0 +1,6 @@ +contract Foo { + function f(uint[] storage memory constant x, uint[] memory calldata y) internal { } +} +// ---- +// ParserError: (45-51): Location already specified. +// ParserError: (78-86): Location already specified. diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_state_variables_multi.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_state_variables_multi.sol new file mode 100644 index 00000000..e34df2b2 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_state_variables_multi.sol @@ -0,0 +1,5 @@ +contract Foo { + uint[] memory storage calldata x; +} +// ---- +// ParserError: (23-29): Expected identifier but got 'memory' diff --git a/test/libsolidity/syntaxTests/parsing/pragma_illegal.sol b/test/libsolidity/syntaxTests/parsing/pragma_illegal.sol new file mode 100644 index 00000000..3395f6be --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/pragma_illegal.sol @@ -0,0 +1,4 @@ +pragma ``; +// ---- +// ParserError: (7-8): Token incompatible with Solidity parser as part of pragma directive. +// ParserError: (8-9): Token incompatible with Solidity parser as part of pragma directive. diff --git a/test/libsolidity/syntaxTests/pragma/invalid_pragma.sol b/test/libsolidity/syntaxTests/pragma/invalid_pragma.sol new file mode 100644 index 00000000..cb2585ba --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/invalid_pragma.sol @@ -0,0 +1,3 @@ +pragma 0; +// ---- +// SyntaxError: (0-9): Invalid pragma "0" diff --git a/test/libsolidity/syntaxTests/pragma/unknown_pragma.sol b/test/libsolidity/syntaxTests/pragma/unknown_pragma.sol new file mode 100644 index 00000000..3a48eddd --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/unknown_pragma.sol @@ -0,0 +1,3 @@ +pragma thisdoesntexist; +// ---- +// SyntaxError: (0-23): Unknown pragma "thisdoesntexist" diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol index 24327db0..898ee8ba 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_event.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol @@ -1,4 +1,3 @@ -pragma solidity ^0.4.3; contract C { event SomeEvent(); function a() public { @@ -6,4 +5,4 @@ contract C { } } // ---- -// ParserError: (95-99): Expected primary expression. +// ParserError: (71-75): Expected primary expression. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol index ff31d440..a898f84a 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_function.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol @@ -1,4 +1,3 @@ -pragma solidity ^0.4.3; contract C { function f() private pure {} function a() public pure { @@ -8,5 +7,5 @@ contract C { } } // ---- -// TypeError: (162-165): Tuple component cannot be empty. -// TypeError: (181-184): Tuple component cannot be empty. +// TypeError: (138-141): Tuple component cannot be empty. +// TypeError: (157-160): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol index 3d252f0b..63b039cd 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol @@ -1,4 +1,3 @@ -pragma solidity ^0.4.3; contract C { function f() private pure {} function a() public { @@ -8,6 +7,6 @@ contract C { } } // ---- -// TypeError: (146-149): Tuple component cannot be empty. -// TypeError: (151-154): Tuple component cannot be empty. -// TypeError: (145-155): Type tuple(tuple(),tuple()) is not implicitly convertible to expected type tuple(uint256,uint256). +// TypeError: (122-125): Tuple component cannot be empty. +// TypeError: (127-130): Tuple component cannot be empty. +// TypeError: (121-131): Type tuple(tuple(),tuple()) is not implicitly convertible to expected type tuple(uint256,uint256). diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol index f8b2ae7e..9bc21561 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol @@ -1,4 +1,3 @@ -pragma solidity ^0.4.3; contract C { function f() private pure {} function a() public { @@ -8,4 +7,4 @@ contract C { } } // ---- -// TypeError: (146-149): Array component cannot be empty. +// TypeError: (122-125): Array component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_calldata.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_calldata.sol new file mode 100644 index 00000000..c73c7f32 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_calldata.sol @@ -0,0 +1,9 @@ +contract c { + mapping(uint => uint) y; + function f() view public { + mapping(uint => uint) calldata x = y; + x; + } +} +// ---- +// TypeError: (81-113): Data location for mappings must be specified as "storage". diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_default.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_default.sol new file mode 100644 index 00000000..85531ae1 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_default.sol @@ -0,0 +1,9 @@ +contract c { + mapping(uint => uint) y; + function f() view public { + mapping(uint => uint) x = y; + x; + } +} +// ---- +// TypeError: (81-104): Data location for mappings must be specified as "storage". diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_memory.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_memory.sol new file mode 100644 index 00000000..7151e887 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_memory.sol @@ -0,0 +1,9 @@ +contract c { + mapping(uint => uint) y; + function f() view public { + mapping(uint => uint) memory x = y; + x; + } +} +// ---- +// TypeError: (81-111): Data location for mappings must be specified as "storage". diff --git a/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol b/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol index 7ed92b58..36b3df9f 100644 --- a/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol +++ b/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol @@ -1,5 +1,3 @@ -pragma solidity ^0.4.20; - contract C { function f() internal pure {} function g() internal pure returns (uint) { return 1; } @@ -13,6 +11,6 @@ contract C { } // ---- -// SyntaxError: (249-261): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. -// SyntaxError: (271-283): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. -// SyntaxError: (293-306): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. +// SyntaxError: (223-235): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. +// SyntaxError: (245-257): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. +// SyntaxError: (267-280): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index ed4f148e..bd4b0db9 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -119,7 +119,7 @@ TestTool::Result TestTool::process() "Exception during syntax test: " << _e.what() << endl; return Result::Exception; } - catch(...) + catch (...) { FormattedScope(cout, m_formatted, {BOLD, RED}) << "Unknown exception during syntax test." << endl; |