mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow using overloaded functions as literal suffixes
This commit is contained in:
@@ -214,13 +214,6 @@
|
||||
],
|
||||
"expression":
|
||||
{
|
||||
"argumentTypes":
|
||||
[
|
||||
{
|
||||
"typeIdentifier": "t_rational_123345789_by_1000000",
|
||||
"typeString": "rational_const 123345789 / 1000000"
|
||||
}
|
||||
],
|
||||
"id": 13,
|
||||
"name": "str",
|
||||
"nodeType": "Identifier",
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
function suffix(uint x) pure suffix returns (uint) { return x; }
|
||||
function suffix(bool x) pure suffix returns (bool) { return x; }
|
||||
function suffix(address x) pure suffix returns (address) { return x; }
|
||||
function suffix(string memory x) pure suffix returns (string memory) { return x; }
|
||||
|
||||
contract C {
|
||||
function run() public returns (bytes memory) {
|
||||
return abi.encode(
|
||||
42 suffix,
|
||||
true suffix,
|
||||
0x1234567890123456789012345678901234567890 suffix,
|
||||
"a" suffix
|
||||
);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// run() -> 0x20, 0xc0, 0x2a, 1, 0x1234567890123456789012345678901234567890, 0x80, 1, "a"
|
||||
@@ -5,7 +5,6 @@ function suffix(string memory) pure suffix returns (string memory) {}
|
||||
|
||||
contract C {
|
||||
int a = 1 suffix;
|
||||
bool b = true suffix;
|
||||
address c = 0x1234567890123456789012345678901234567890 suffix;
|
||||
string d = "a" suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (259-265): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// TypeError 2998: (74-89): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
|
||||
// TypeError 7407: (170-219): Type address is not implicitly convertible to expected type address payable.
|
||||
// TypeError 2144: (213-219): No matching declaration found after variable lookup.
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
function s(uint) pure suffix returns (uint) {}
|
||||
function s(string memory) pure returns (string memory) {}
|
||||
|
||||
contract C {
|
||||
function run() public pure {
|
||||
"a" s;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (164-165): No matching declaration found after variable lookup.
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
function s(uint) pure suffix returns (uint) {}
|
||||
function s(string memory) pure returns (string memory) {}
|
||||
|
||||
contract C {
|
||||
function run() public pure {
|
||||
1 s;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (162-163): No matching declaration found after variable lookup.
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
function s(uint) pure suffix returns (uint) {}
|
||||
function s(string memory) pure returns (string memory) {}
|
||||
|
||||
contract C {
|
||||
function run() public pure {
|
||||
1 s; // OK
|
||||
s(1); // OK
|
||||
"a" s; // not allowed
|
||||
s("a"); // OK
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (208-209): No matching declaration found after argument-dependent lookup.
|
||||
-4
@@ -6,14 +6,10 @@ function f(string memory) pure suffix returns (string memory) {}
|
||||
|
||||
contract C {
|
||||
function run() public pure {
|
||||
1 s;
|
||||
s(1);
|
||||
//"a" s; // not allowed
|
||||
s("a");
|
||||
|
||||
//1 f; // not allowed
|
||||
f(1);
|
||||
"a" f;
|
||||
f("a");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
int32 a = 115792089237316195423570985008687907853269984665640564039457584007913129639936 uSuffix; // 2**256
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (229-236): No matching declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (229-236): No matching declaration found after variable lookup.
|
||||
|
||||
+2
-13
@@ -1,19 +1,8 @@
|
||||
function uSuffix(uint8, uint) pure suffix returns (uint) {}
|
||||
function uSuffix(uint16, uint) pure suffix returns (int) {}
|
||||
|
||||
function iSuffix(int8, uint) pure suffix returns (uint) {}
|
||||
function iSuffix(int16, uint) pure suffix returns (int) {}
|
||||
|
||||
function iuSuffix(uint8, uint) pure suffix returns (int) {}
|
||||
function iuSuffix(int8, uint) pure suffix returns (uint) {}
|
||||
|
||||
contract C {
|
||||
int a = 1.024 uSuffix;
|
||||
int b = 1.024 iSuffix;
|
||||
|
||||
int c = -1.024 uSuffix;
|
||||
int d = -1.024 iSuffix;
|
||||
|
||||
int e = 2.55 iuSuffix;
|
||||
int f = -2.55 iuSuffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (152-159): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
uint a = 1.27 iuSuffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (151-159): No unique declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (151-159): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
uint a = 1.27 uSuffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (151-158): No unique declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (151-158): No matching declaration found after variable lookup.
|
||||
|
||||
+3
-20
@@ -1,31 +1,14 @@
|
||||
==== Source: A.sol ====
|
||||
function s(uint, uint) pure suffix returns (uint) {}
|
||||
|
||||
function f(uint, uint) pure returns (uint) {}
|
||||
|
||||
==== Source: B.sol ====
|
||||
import "A.sol";
|
||||
import {s} from "A.sol";
|
||||
|
||||
function s(string memory) pure returns (string memory) {}
|
||||
|
||||
function f(string memory) pure suffix returns (string memory) {}
|
||||
|
||||
contract C {
|
||||
function run() public pure {
|
||||
1024 s;
|
||||
"a" f;
|
||||
}
|
||||
}
|
||||
==== Source: C.sol ====
|
||||
import {s, f} from "A.sol";
|
||||
|
||||
function s(string memory) pure returns (string memory) {}
|
||||
|
||||
function f(string memory) pure suffix returns (string memory) {}
|
||||
|
||||
contract D {
|
||||
function run() public pure {
|
||||
1024 s;
|
||||
"a" f;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (B.sol:144-145): No matching declaration found after variable lookup.
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
function suffix256(uint) pure suffix returns (bool) {}
|
||||
function suffix256(uint, uint) pure suffix returns (address) {}
|
||||
|
||||
function suffix8(uint) pure suffix returns (bool) {}
|
||||
function suffix8(uint8, uint) pure suffix returns (address) {}
|
||||
|
||||
contract C {
|
||||
// Not ambiguous: no way to convert 1.1 into uint.
|
||||
address a = 1.1 suffix256;
|
||||
|
||||
// Not ambiguous: 1024 won't fit into uint8.
|
||||
bool b = 1024 suffix8;
|
||||
}
|
||||
+1
-1
@@ -7,4 +7,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (176-182): No unique declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (176-182): No matching declaration found after variable lookup.
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
function suffix256(uint) pure suffix returns (bool) {}
|
||||
function suffix256(uint, uint) pure suffix returns (address) {}
|
||||
|
||||
contract C {
|
||||
address a = 1.1 suffix256;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (153-162): No matching declaration found after variable lookup.
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
function suffix8(uint) pure suffix returns (bool) {}
|
||||
function suffix8(uint8, uint) pure suffix returns (address) {}
|
||||
|
||||
contract C {
|
||||
bool b = 1024 suffix8;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (148-155): No matching declaration found after variable lookup.
|
||||
+2
-13
@@ -1,19 +1,8 @@
|
||||
function uSuffix(uint8) pure suffix returns (uint) {}
|
||||
function uSuffix(uint16) pure suffix returns (int) {}
|
||||
|
||||
function iSuffix(int8) pure suffix returns (uint) {}
|
||||
function iSuffix(int16) pure suffix returns (int) {}
|
||||
|
||||
function iuSuffix(uint8) pure suffix returns (int) {}
|
||||
function iuSuffix(int8) pure suffix returns (uint) {}
|
||||
|
||||
contract C {
|
||||
int a = 1024 uSuffix;
|
||||
int b = 1024 iSuffix;
|
||||
|
||||
int c = -1024 uSuffix;
|
||||
int d = -1024 iSuffix;
|
||||
|
||||
int e = 255 iuSuffix;
|
||||
int f = -255 iuSuffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (139-146): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
int a = 127 iuSuffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (137-145): No unique declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (137-145): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
int a = 127 uSuffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (137-144): No unique declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (137-144): No matching declaration found after variable lookup.
|
||||
|
||||
@@ -9,7 +9,6 @@ import "A.sol" as A;
|
||||
|
||||
contract C {
|
||||
int a = 1 A.suffix;
|
||||
bool b = true A.suffix;
|
||||
address c = 0x1234567890123456789012345678901234567890 A.suffix;
|
||||
string d = "a" A.suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 6675: (B.sol:49-57): Member "suffix" not unique after argument-dependent lookup in module "A.sol".
|
||||
|
||||
+2
@@ -4,3 +4,5 @@ function suffix(bytes memory) pure suffix returns (bytes memory) {}
|
||||
contract C {
|
||||
bytes a = hex"abcd" suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (176-182): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
uint a = "abcd" suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (155-161): No unique declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (155-161): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -11,4 +11,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9582: (218-226): Member "suffix" not found or not visible after argument-dependent lookup in uint8.
|
||||
// TypeError 6675: (218-226): Member "suffix" not unique after argument-dependent lookup in uint8.
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ abstract contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (194-200): No matching declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (194-200): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
function suffix(address) public pure returns (uint) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (31-37): No matching declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (31-37): No matching declaration found after variable lookup.
|
||||
|
||||
+1
-1
@@ -4,4 +4,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (54-60): No matching declaration found after argument-dependent lookup.
|
||||
// TypeError 2144: (54-60): No matching declaration found after variable lookup.
|
||||
|
||||
Reference in New Issue
Block a user