mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow user-defined types as mapping keys in parser and restrict to contracts during type checking.
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"exportedSymbols":
|
||||
{
|
||||
"C":
|
||||
[
|
||||
17
|
||||
]
|
||||
},
|
||||
"id": 18,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"abstract": false,
|
||||
"baseContracts": [],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 17,
|
||||
"linearizedBaseContracts":
|
||||
[
|
||||
17
|
||||
],
|
||||
"name": "C",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"canonicalName": "C.E",
|
||||
"id": 4,
|
||||
"members":
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "A",
|
||||
"nodeType": "EnumValue",
|
||||
"src": "26:1:1"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "B",
|
||||
"nodeType": "EnumValue",
|
||||
"src": "29:1:1"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "C",
|
||||
"nodeType": "EnumValue",
|
||||
"src": "32:1:1"
|
||||
}
|
||||
],
|
||||
"name": "E",
|
||||
"nodeType": "EnumDefinition",
|
||||
"src": "17:18:1"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 8,
|
||||
"name": "a",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"overrides": null,
|
||||
"scope": 17,
|
||||
"src": "40:20:1",
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_contract$_C_$17_$_t_bool_$",
|
||||
"typeString": "mapping(contract C => bool)"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 7,
|
||||
"keyType":
|
||||
{
|
||||
"contractScope": null,
|
||||
"id": 5,
|
||||
"name": "C",
|
||||
"nodeType": "UserDefinedTypeName",
|
||||
"referencedDeclaration": 17,
|
||||
"src": "48:1:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_contract$_C_$17",
|
||||
"typeString": "contract C"
|
||||
}
|
||||
},
|
||||
"nodeType": "Mapping",
|
||||
"src": "40:18:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_contract$_C_$17_$_t_bool_$",
|
||||
"typeString": "mapping(contract C => bool)"
|
||||
},
|
||||
"valueType":
|
||||
{
|
||||
"id": 6,
|
||||
"name": "bool",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "53:4:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 12,
|
||||
"name": "b",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"overrides": null,
|
||||
"scope": 17,
|
||||
"src": "66:26:1",
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_address_$_t_bool_$",
|
||||
"typeString": "mapping(address => bool)"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 11,
|
||||
"keyType":
|
||||
{
|
||||
"id": 9,
|
||||
"name": "address",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "74:7:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"nodeType": "Mapping",
|
||||
"src": "66:24:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_address_$_t_bool_$",
|
||||
"typeString": "mapping(address => bool)"
|
||||
},
|
||||
"valueType":
|
||||
{
|
||||
"id": 10,
|
||||
"name": "bool",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "85:4:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 16,
|
||||
"name": "c",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"overrides": null,
|
||||
"scope": 17,
|
||||
"src": "98:20:1",
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_enum$_E_$4_$_t_bool_$",
|
||||
"typeString": "mapping(enum C.E => bool)"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 15,
|
||||
"keyType":
|
||||
{
|
||||
"contractScope": null,
|
||||
"id": 13,
|
||||
"name": "E",
|
||||
"nodeType": "UserDefinedTypeName",
|
||||
"referencedDeclaration": 4,
|
||||
"src": "106:1:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_enum$_E_$4",
|
||||
"typeString": "enum C.E"
|
||||
}
|
||||
},
|
||||
"nodeType": "Mapping",
|
||||
"src": "98:18:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_enum$_E_$4_$_t_bool_$",
|
||||
"typeString": "mapping(enum C.E => bool)"
|
||||
},
|
||||
"valueType":
|
||||
{
|
||||
"id": 14,
|
||||
"name": "bool",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "111:4:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"scope": 18,
|
||||
"src": "0:121:1"
|
||||
}
|
||||
],
|
||||
"src": "0:122:1"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
enum E { A, B, C }
|
||||
mapping(C => bool) a;
|
||||
mapping(address => bool) b;
|
||||
mapping(E => bool) c;
|
||||
}
|
||||
|
||||
// ----
|
||||
@@ -0,0 +1,248 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"exportedSymbols":
|
||||
{
|
||||
"C":
|
||||
[
|
||||
17
|
||||
]
|
||||
}
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"abstract": false,
|
||||
"baseContracts":
|
||||
[
|
||||
null
|
||||
],
|
||||
"contractDependencies":
|
||||
[
|
||||
null
|
||||
],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"linearizedBaseContracts":
|
||||
[
|
||||
17
|
||||
],
|
||||
"name": "C",
|
||||
"scope": 18
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"canonicalName": "C.E",
|
||||
"name": "E"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "A"
|
||||
},
|
||||
"id": 1,
|
||||
"name": "EnumValue",
|
||||
"src": "26:1:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "B"
|
||||
},
|
||||
"id": 2,
|
||||
"name": "EnumValue",
|
||||
"src": "29:1:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "C"
|
||||
},
|
||||
"id": 3,
|
||||
"name": "EnumValue",
|
||||
"src": "32:1:1"
|
||||
}
|
||||
],
|
||||
"id": 4,
|
||||
"name": "EnumDefinition",
|
||||
"src": "17:18:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"constant": false,
|
||||
"name": "a",
|
||||
"overrides": null,
|
||||
"scope": 17,
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"type": "mapping(contract C => bool)",
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"type": "mapping(contract C => bool)"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"contractScope": null,
|
||||
"name": "C",
|
||||
"referencedDeclaration": 17,
|
||||
"type": "contract C"
|
||||
},
|
||||
"id": 5,
|
||||
"name": "UserDefinedTypeName",
|
||||
"src": "48:1:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "bool",
|
||||
"type": "bool"
|
||||
},
|
||||
"id": 6,
|
||||
"name": "ElementaryTypeName",
|
||||
"src": "53:4:1"
|
||||
}
|
||||
],
|
||||
"id": 7,
|
||||
"name": "Mapping",
|
||||
"src": "40:18:1"
|
||||
}
|
||||
],
|
||||
"id": 8,
|
||||
"name": "VariableDeclaration",
|
||||
"src": "40:20:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"constant": false,
|
||||
"name": "b",
|
||||
"overrides": null,
|
||||
"scope": 17,
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"type": "mapping(address => bool)",
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"type": "mapping(address => bool)"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "address",
|
||||
"type": "address"
|
||||
},
|
||||
"id": 9,
|
||||
"name": "ElementaryTypeName",
|
||||
"src": "74:7:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "bool",
|
||||
"type": "bool"
|
||||
},
|
||||
"id": 10,
|
||||
"name": "ElementaryTypeName",
|
||||
"src": "85:4:1"
|
||||
}
|
||||
],
|
||||
"id": 11,
|
||||
"name": "Mapping",
|
||||
"src": "66:24:1"
|
||||
}
|
||||
],
|
||||
"id": 12,
|
||||
"name": "VariableDeclaration",
|
||||
"src": "66:26:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"constant": false,
|
||||
"name": "c",
|
||||
"overrides": null,
|
||||
"scope": 17,
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"type": "mapping(enum C.E => bool)",
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"type": "mapping(enum C.E => bool)"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"contractScope": null,
|
||||
"name": "E",
|
||||
"referencedDeclaration": 4,
|
||||
"type": "enum C.E"
|
||||
},
|
||||
"id": 13,
|
||||
"name": "UserDefinedTypeName",
|
||||
"src": "106:1:1"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "bool",
|
||||
"type": "bool"
|
||||
},
|
||||
"id": 14,
|
||||
"name": "ElementaryTypeName",
|
||||
"src": "111:4:1"
|
||||
}
|
||||
],
|
||||
"id": 15,
|
||||
"name": "Mapping",
|
||||
"src": "98:18:1"
|
||||
}
|
||||
],
|
||||
"id": 16,
|
||||
"name": "VariableDeclaration",
|
||||
"src": "98:20:1"
|
||||
}
|
||||
],
|
||||
"id": 17,
|
||||
"name": "ContractDefinition",
|
||||
"src": "0:121:1"
|
||||
}
|
||||
],
|
||||
"id": 18,
|
||||
"name": "SourceUnit",
|
||||
"src": "0:122:1"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
interface A {}
|
||||
contract test {
|
||||
mapping(A => uint8) table;
|
||||
function get(A k) public returns (uint8 v) {
|
||||
return table[k];
|
||||
}
|
||||
function set(A k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// get(address): 0 -> 0
|
||||
// get(address): 0x01 -> 0
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x01, 0xa1 ->
|
||||
// get(address): 0 -> 0
|
||||
// get(address): 0x01 -> 0xa1
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x00, 0xef ->
|
||||
// get(address): 0 -> 0xef
|
||||
// get(address): 0x01 -> 0xa1
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x01, 0x05 ->
|
||||
// get(address): 0 -> 0xef
|
||||
// get(address): 0x01 -> 0x05
|
||||
// get(address): 0xa7 -> 0
|
||||
@@ -0,0 +1,38 @@
|
||||
interface A {}
|
||||
contract test {
|
||||
mapping(A => uint8) public table;
|
||||
function set(A k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
function get(A k) public returns (uint8) {
|
||||
return this.table(k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// table(address): 0 -> 0
|
||||
// table(address): 0x01 -> 0
|
||||
// table(address): 0xa7 -> 0
|
||||
// get(address): 0 -> 0
|
||||
// get(address): 0x01 -> 0
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x01, 0xa1 ->
|
||||
// table(address): 0 -> 0
|
||||
// table(address): 0x01 -> 0xa1
|
||||
// table(address): 0xa7 -> 0
|
||||
// get(address): 0 -> 0
|
||||
// get(address): 0x01 -> 0xa1
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x00, 0xef ->
|
||||
// table(address): 0 -> 0xef
|
||||
// table(address): 0x01 -> 0xa1
|
||||
// table(address): 0xa7 -> 0
|
||||
// get(address): 0 -> 0xef
|
||||
// get(address): 0x01 -> 0xa1
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x01, 0x05 ->
|
||||
// table(address): 0 -> 0xef
|
||||
// table(address): 0x01 -> 0x05
|
||||
// table(address): 0xa7 -> 0
|
||||
// get(address): 0 -> 0xef
|
||||
// get(address): 0x01 -> 0x05
|
||||
// get(address): 0xa7 -> 0
|
||||
@@ -0,0 +1,35 @@
|
||||
interface A {}
|
||||
library L {
|
||||
function get(mapping(A => uint8) storage table, A k) external returns (uint8) {
|
||||
return table[k];
|
||||
}
|
||||
function set(mapping(A => uint8) storage table, A k, uint8 v) external {
|
||||
table[k] = v;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
mapping(A => uint8) table;
|
||||
function get(A k) public returns (uint8 v) {
|
||||
return L.get(table, k);
|
||||
}
|
||||
function set(A k, uint8 v) public {
|
||||
L.set(table, k, v);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// library: L
|
||||
// get(address): 0 -> 0
|
||||
// get(address): 0x01 -> 0
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x01, 0xa1 ->
|
||||
// get(address): 0 -> 0
|
||||
// get(address): 0x01 -> 0xa1
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x00, 0xef ->
|
||||
// get(address): 0 -> 0xef
|
||||
// get(address): 0x01 -> 0xa1
|
||||
// get(address): 0xa7 -> 0
|
||||
// set(address,uint8): 0x01, 0x05 ->
|
||||
// get(address): 0 -> 0xef
|
||||
// get(address): 0x01 -> 0x05
|
||||
// get(address): 0xa7 -> 0
|
||||
@@ -0,0 +1,30 @@
|
||||
enum E { A, B, C }
|
||||
contract test {
|
||||
mapping(E => uint8) table;
|
||||
function get(E k) public returns (uint8 v) {
|
||||
return table[k];
|
||||
}
|
||||
function set(E k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0
|
||||
// get(uint8): 0x02 -> 0
|
||||
// get(uint8): 0x03 -> FAILURE
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0xa1 ->
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x00, 0xef ->
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0x05 ->
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0x05
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
@@ -0,0 +1,38 @@
|
||||
contract test {
|
||||
enum E { A, B, C }
|
||||
mapping(E => uint8) public table;
|
||||
function set(E k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
function get(E k) public returns (uint8) {
|
||||
return this.table(k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// table(uint8): 0 -> 0
|
||||
// table(uint8): 0x01 -> 0
|
||||
// table(uint8): 0xa7 -> 0
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0xa1 ->
|
||||
// table(uint8): 0 -> 0
|
||||
// table(uint8): 0x01 -> 0xa1
|
||||
// table(uint8): 0xa7 -> 0
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x00, 0xef ->
|
||||
// table(uint8): 0 -> 0xef
|
||||
// table(uint8): 0x01 -> 0xa1
|
||||
// table(uint8): 0xa7 -> 0
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0x05 ->
|
||||
// table(uint8): 0 -> 0xef
|
||||
// table(uint8): 0x01 -> 0x05
|
||||
// table(uint8): 0xa7 -> 0
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0x05
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
@@ -0,0 +1,39 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
contract test {
|
||||
enum E { A, B, C }
|
||||
mapping(E => uint8) public table;
|
||||
function set(E k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
function get(E k) public returns (uint8) {
|
||||
return this.table(k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// table(uint8): 0 -> 0
|
||||
// table(uint8): 0x01 -> 0
|
||||
// table(uint8): 0xa7 -> FAILURE
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0xa1 ->
|
||||
// table(uint8): 0 -> 0
|
||||
// table(uint8): 0x01 -> 0xa1
|
||||
// table(uint8): 0xa7 -> FAILURE
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x00, 0xef ->
|
||||
// table(uint8): 0 -> 0xef
|
||||
// table(uint8): 0x01 -> 0xa1
|
||||
// table(uint8): 0xa7 -> FAILURE
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0x05 ->
|
||||
// table(uint8): 0 -> 0xef
|
||||
// table(uint8): 0x01 -> 0x05
|
||||
// table(uint8): 0xa7 -> FAILURE
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0x05
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
@@ -0,0 +1,35 @@
|
||||
enum E { A, B, C }
|
||||
library L {
|
||||
function get(mapping(E => uint8) storage table, E k) external returns (uint8) {
|
||||
return table[k];
|
||||
}
|
||||
function set(mapping(E => uint8) storage table, E k, uint8 v) external {
|
||||
table[k] = v;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
mapping(E => uint8) table;
|
||||
function get(E k) public returns (uint8 v) {
|
||||
return L.get(table, k);
|
||||
}
|
||||
function set(E k, uint8 v) public {
|
||||
L.set(table, k, v);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// library: L
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0xa1 ->
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x00, 0xef ->
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
// set(uint8,uint8): 0x01, 0x05 ->
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0x05
|
||||
// get(uint8): 0xa7 -> FAILURE
|
||||
@@ -0,0 +1,9 @@
|
||||
interface I {}
|
||||
contract J {}
|
||||
contract C {
|
||||
mapping(I => bool) i;
|
||||
mapping(J => bool) j;
|
||||
function f(I x, J y) public view returns (bool, bool) {
|
||||
return (i[x], j[y]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
interface I {}
|
||||
contract J {}
|
||||
contract C {
|
||||
mapping(I => bool) i;
|
||||
mapping(J => bool) j;
|
||||
function f(I x, J y, address z) public view returns (bool, bool, bool) {
|
||||
return (i[y], j[x], i[z]);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (189-190): Type contract J is not implicitly convertible to expected type contract I.
|
||||
// TypeError: (195-196): Type contract I is not implicitly convertible to expected type contract J.
|
||||
// TypeError: (201-202): Type address is not implicitly convertible to expected type contract I.
|
||||
@@ -0,0 +1,7 @@
|
||||
enum E { A, B, C }
|
||||
contract C {
|
||||
mapping(E => bool) e;
|
||||
function f(E v) public view returns (bool, bool) {
|
||||
return (e[v], e[E.A]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
enum E { A, B, C }
|
||||
contract C {
|
||||
mapping(E => bool) e;
|
||||
function f(uint256 a, uint8 b) public view returns (bool, bool) {
|
||||
return (e[a], e[b]);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (146-147): Type uint256 is not implicitly convertible to expected type enum E.
|
||||
// TypeError: (152-153): Type uint8 is not implicitly convertible to expected type enum E.
|
||||
@@ -5,4 +5,4 @@ contract c {
|
||||
mapping(S => uint) data;
|
||||
}
|
||||
// ----
|
||||
// ParserError: (47-48): Expected elementary type name for mapping key type
|
||||
// TypeError: (47-48): Only elementary types, contract types or enums are allowed as mapping keys.
|
||||
|
||||
@@ -5,4 +5,4 @@ contract c {
|
||||
mapping(S => uint) data;
|
||||
}
|
||||
// ----
|
||||
// ParserError: (49-50): Expected elementary type name for mapping key type
|
||||
// TypeError: (49-50): Only elementary types, contract types or enums are allowed as mapping keys.
|
||||
|
||||
@@ -4,4 +4,4 @@ contract test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (44-47): Expected elementary type name for mapping key type
|
||||
// ParserError: (44-47): Expected elementary type name or identifier for mapping key type
|
||||
|
||||
Reference in New Issue
Block a user