mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
New tests.
This commit is contained in:
parent
b2f1d558da
commit
34e7ae6ff9
@ -0,0 +1,9 @@
|
||||
address constant e = 0x1212121212121212121212121000002134593163;
|
||||
|
||||
contract C {
|
||||
function f() public returns (address z) {
|
||||
assembly { z := e }
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> 0x1212121212121212121212121000002134593163
|
@ -3,7 +3,7 @@ bytes constant b = hex"030102";
|
||||
string constant c = "hello";
|
||||
uint256 constant x = 56;
|
||||
enum ActionChoices {GoLeft, GoRight, GoStraight, Sit}
|
||||
ActionChoices constant choices = ActionChoices.GoLeft;
|
||||
ActionChoices constant choices = ActionChoices.GoRight;
|
||||
bytes32 constant st = "abc\x00\xff__";
|
||||
|
||||
contract C {
|
||||
@ -30,3 +30,4 @@ contract C {
|
||||
// f() -> 0x20, 3, "\x03\x01\x02"
|
||||
// g() -> 0x20, 3, "\x03\x01\x02"
|
||||
// h() -> 0x20, 5, "hello"
|
||||
// i() -> 0x38, 1, 0x61626300ff5f5f00000000000000000000000000000000000000000000000000
|
||||
|
@ -0,0 +1,41 @@
|
||||
==== Source: s1.sol ====
|
||||
|
||||
|
||||
bytes constant a = b;
|
||||
bytes constant b = hex"030102";
|
||||
|
||||
function fre() pure returns (bytes memory) {
|
||||
return a;
|
||||
}
|
||||
|
||||
==== Source: s2.sol ====
|
||||
|
||||
import "s1.sol";
|
||||
|
||||
uint256 constant c = uint8(a[0]) + 2;
|
||||
|
||||
contract C {
|
||||
function f() public returns (bytes memory) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function g() public returns (bytes memory) {
|
||||
return b;
|
||||
}
|
||||
|
||||
function h() public returns (uint) {
|
||||
return c;
|
||||
}
|
||||
|
||||
function i() public returns (bytes memory) {
|
||||
return fre();
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x20, 3, "\x03\x01\x02"
|
||||
// g() -> 0x20, 3, "\x03\x01\x02"
|
||||
// h() -> 5
|
||||
// i() -> 0x20, 3, "\x03\x01\x02"
|
@ -0,0 +1,26 @@
|
||||
==== Source: s1.sol ====
|
||||
|
||||
|
||||
uint constant a = 89;
|
||||
|
||||
function fre() pure returns (uint) {
|
||||
return a;
|
||||
}
|
||||
|
||||
==== Source: s2.sol ====
|
||||
|
||||
import {a as b, fre} from "s1.sol";
|
||||
import "s1.sol" as M;
|
||||
|
||||
uint256 constant a = 13;
|
||||
|
||||
contract C {
|
||||
function f() public returns (uint, uint, uint, uint) {
|
||||
return (a, fre(), M.a, b);
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x0d, 0x59, 0x59, 0x59
|
@ -0,0 +1,15 @@
|
||||
==== Source: a.sol ====
|
||||
function f(uint) pure returns (uint) { return 7; }
|
||||
function f(bytes memory x) pure returns (uint) { return x.length; }
|
||||
==== Source: b.sol ====
|
||||
import "a.sol" as M;
|
||||
contract C {
|
||||
function f() public pure returns (uint, uint) {
|
||||
return (M.f(2), M.f("abc"));
|
||||
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 7, 3
|
@ -0,0 +1,3 @@
|
||||
/// @dev Documentation
|
||||
uint constant x = 8;
|
||||
// ----
|
@ -0,0 +1,4 @@
|
||||
/// Documentation
|
||||
uint constant x = 8;
|
||||
// ----
|
||||
// DocstringParsingError 6546: (0-18): Documentation tag @notice not valid for file-level variables.
|
@ -0,0 +1,3 @@
|
||||
uint constant override x = 2;
|
||||
// ----
|
||||
// ParserError 2314: (14-22): Expected identifier but got 'override'
|
@ -0,0 +1,3 @@
|
||||
uint constant x;
|
||||
// ----
|
||||
// TypeError 4266: (0-15): Uninitialized "constant" variable.
|
@ -0,0 +1,3 @@
|
||||
uint constant virtual x;
|
||||
// ----
|
||||
// ParserError 2314: (14-21): Expected identifier but got 'virtual'
|
@ -0,0 +1,3 @@
|
||||
uint public constant x = 7;
|
||||
// ----
|
||||
// ParserError 2314: (5-11): Expected identifier but got 'public'
|
@ -0,0 +1,3 @@
|
||||
uint constant public y = 7;
|
||||
// ----
|
||||
// ParserError 2314: (14-20): Expected identifier but got 'public'
|
15
test/libsolidity/syntaxTests/constants/cross_file_cyclic.sol
Normal file
15
test/libsolidity/syntaxTests/constants/cross_file_cyclic.sol
Normal file
@ -0,0 +1,15 @@
|
||||
==== Source: a ====
|
||||
import "b";
|
||||
uint constant c = d;
|
||||
==== Source: b ====
|
||||
import "a";
|
||||
uint constant b = c;
|
||||
uint constant d = b;
|
||||
contract C {
|
||||
uint constant a = b;
|
||||
}
|
||||
// ----
|
||||
// TypeError 6161: (b:12-31): The value of the constant b has a cyclic dependency via c.
|
||||
// TypeError 6161: (b:33-52): The value of the constant d has a cyclic dependency via b.
|
||||
// TypeError 6161: (b:71-90): The value of the constant a has a cyclic dependency via b.
|
||||
// TypeError 6161: (a:12-31): The value of the constant c has a cyclic dependency via d.
|
@ -0,0 +1,15 @@
|
||||
==== Source: a ====
|
||||
import "b";
|
||||
uint constant c = d;
|
||||
==== Source: b ====
|
||||
import "a" as M;
|
||||
uint constant b = M.c;
|
||||
uint constant d = b;
|
||||
contract C {
|
||||
uint constant a = b;
|
||||
}
|
||||
// ----
|
||||
// TypeError 6161: (b:17-38): The value of the constant b has a cyclic dependency via c.
|
||||
// TypeError 6161: (b:40-59): The value of the constant d has a cyclic dependency via b.
|
||||
// TypeError 6161: (b:78-97): The value of the constant a has a cyclic dependency via b.
|
||||
// TypeError 6161: (a:12-31): The value of the constant c has a cyclic dependency via d.
|
@ -0,0 +1,3 @@
|
||||
uint[] memory constant x = 2;
|
||||
// ----
|
||||
// ParserError 2314: (7-13): Expected identifier but got 'memory'
|
@ -0,0 +1,3 @@
|
||||
uint[] constant memory x = 2;
|
||||
// ----
|
||||
// ParserError 2314: (16-22): Expected identifier but got 'memory'
|
@ -0,0 +1,4 @@
|
||||
uint immutable x = 7;
|
||||
// ----
|
||||
// DeclarationError 8342: (0-20): Only constant variables are allowed at file level.
|
||||
// DeclarationError 8297: (0-20): The "immutable" keyword can only be used for state variables.
|
@ -0,0 +1,3 @@
|
||||
mapping(uint => uint) constant b = b;
|
||||
// ----
|
||||
// TypeError 9259: (0-36): Constants of non-value type not yet implemented.
|
@ -0,0 +1,7 @@
|
||||
==== Source: a ====
|
||||
uint constant c = 7;
|
||||
==== Source: b ====
|
||||
import {c as d} from "a";
|
||||
uint constant d = 7;
|
||||
// ----
|
||||
// DeclarationError 2333: (b:26-45): Identifier already declared.
|
3
test/libsolidity/syntaxTests/constants/non_constant.sol
Normal file
3
test/libsolidity/syntaxTests/constants/non_constant.sol
Normal file
@ -0,0 +1,3 @@
|
||||
uint x = 7;
|
||||
// ----
|
||||
// DeclarationError 8342: (0-10): Only constant variables are allowed at file level.
|
@ -0,0 +1,8 @@
|
||||
==== Source: a ====
|
||||
import "b";
|
||||
uint constant c = 7;
|
||||
==== Source: b ====
|
||||
import "a";
|
||||
uint constant c = 7;
|
||||
// ----
|
||||
// DeclarationError 2333: (b:12-31): Identifier already declared.
|
@ -0,0 +1,4 @@
|
||||
uint constant c = 7;
|
||||
uint constant c = 8;
|
||||
// ----
|
||||
// DeclarationError 2333: (21-40): Identifier already declared.
|
@ -0,0 +1,5 @@
|
||||
struct S { uint x; }
|
||||
S constant s;
|
||||
// ----
|
||||
// TypeError 9259: (21-33): Constants of non-value type not yet implemented.
|
||||
// TypeError 4266: (21-33): Uninitialized "constant" variable.
|
@ -0,0 +1,4 @@
|
||||
uint constant c = 7;
|
||||
function c() returns (uint) {}
|
||||
// ----
|
||||
// DeclarationError 2333: (21-51): Identifier already declared.
|
Loading…
Reference in New Issue
Block a user