mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow Mapping keys to have type UserDefinedValueType.
Also added syntax and semantic test.
This commit is contained in:
parent
952540c3b5
commit
1fa6c71bd0
@ -253,12 +253,13 @@ void DeclarationTypeChecker::endVisit(Mapping const& _mapping)
|
||||
{
|
||||
case Type::Category::Enum:
|
||||
case Type::Category::Contract:
|
||||
case Type::Category::UserDefinedValueType:
|
||||
break;
|
||||
default:
|
||||
m_errorReporter.fatalTypeError(
|
||||
7804_error,
|
||||
typeName->location(),
|
||||
"Only elementary types, contract types or enums are allowed as mapping keys."
|
||||
"Only elementary types, user defined value types, contract types or enums are allowed as mapping keys."
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
type MyInt is int;
|
||||
contract C {
|
||||
mapping(MyInt => int) public m;
|
||||
function set(MyInt key, int value) external {
|
||||
m[key] = value;
|
||||
}
|
||||
function set_unwrapped(int key, int value) external {
|
||||
m[MyInt.wrap(key)] = value;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// set(int256,int256): 1, 1 ->
|
||||
// m(int256): 1 -> 1
|
||||
// set_unwrapped(int256,int256): 1, 2 ->
|
||||
// m(int256): 1 -> 2
|
||||
// m(int256): 2 -> 0
|
@ -5,4 +5,4 @@ contract c {
|
||||
mapping(S => uint) data;
|
||||
}
|
||||
// ----
|
||||
// TypeError 7804: (47-48): Only elementary types, contract types or enums are allowed as mapping keys.
|
||||
// TypeError 7804: (47-48): Only elementary types, user defined value types, contract types or enums are allowed as mapping keys.
|
||||
|
@ -5,4 +5,4 @@ contract c {
|
||||
mapping(S => uint) data;
|
||||
}
|
||||
// ----
|
||||
// TypeError 7804: (49-50): Only elementary types, contract types or enums are allowed as mapping keys.
|
||||
// TypeError 7804: (49-50): Only elementary types, user defined value types, contract types or enums are allowed as mapping keys.
|
||||
|
@ -6,4 +6,4 @@ contract C {
|
||||
function g (S calldata) external view {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7804: (56-57): Only elementary types, contract types or enums are allowed as mapping keys.
|
||||
// TypeError 7804: (56-57): Only elementary types, user defined value types, contract types or enums are allowed as mapping keys.
|
||||
|
@ -0,0 +1,4 @@
|
||||
type MyInt is int;
|
||||
contract C {
|
||||
mapping(MyInt => int) m;
|
||||
}
|
Loading…
Reference in New Issue
Block a user