mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Extend using-for.
This commit is contained in:
@@ -7,4 +7,4 @@ contract C {
|
||||
using S for S;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (113-114): Library name expected.
|
||||
// TypeError 4357: (113-114): Library name expected. If you want to attach a function, use '{...}'.
|
||||
|
||||
@@ -7,4 +7,4 @@ interface I {
|
||||
function g() external;
|
||||
}
|
||||
// ----
|
||||
// TypeError 9088: (60-76): The "using for" directive is not allowed inside interfaces.
|
||||
// SyntaxError 9088: (60-76): The "using for" directive is not allowed inside interfaces.
|
||||
|
||||
@@ -3,4 +3,4 @@ contract C {
|
||||
using D for uint;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (38-39): Library name expected.
|
||||
// TypeError 4357: (38-39): Library name expected. If you want to attach a function, use '{...}'.
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ library L {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (120-121): Library name expected.
|
||||
// TypeError 4357: (120-121): Library name expected. If you want to attach a function, use '{...}'.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
function zero(address) pure returns (address) {
|
||||
return address(0);
|
||||
}
|
||||
|
||||
contract C {
|
||||
using * for *;
|
||||
function f(uint x) pure external returns (uint) {
|
||||
return x.id();
|
||||
}
|
||||
function g(address a) pure external returns (address) {
|
||||
return a.zero();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (156-157): Expected identifier but got '*'
|
||||
@@ -0,0 +1,22 @@
|
||||
==== Source: A ====
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
// we check that the effect of this directive is
|
||||
// limited to this file.
|
||||
using {id} for uint;
|
||||
|
||||
function t() pure {
|
||||
uint y = 2;
|
||||
y = y.id();
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
import "A";
|
||||
|
||||
function f() pure {
|
||||
uint y = 2;
|
||||
y = y.id();
|
||||
}
|
||||
// ----
|
||||
// TypeError 9582: (B:57-61): Member "id" not found or not visible after argument-dependent lookup in uint256.
|
||||
@@ -0,0 +1,6 @@
|
||||
function id(uint16 x) pure returns(uint16) {
|
||||
return x;
|
||||
}
|
||||
contract C {
|
||||
using {id} for uint8;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
function id(uint16 x) pure returns(uint16) {
|
||||
return x;
|
||||
}
|
||||
contract C {
|
||||
using {id} for uint256;
|
||||
}
|
||||
// ----
|
||||
// TypeError 3100: (85-87): The function "id" cannot be bound to the type "uint256" because the type cannot be implicitly converted to the first argument of the function ("uint16").
|
||||
@@ -0,0 +1,12 @@
|
||||
function id(int8 x) pure returns(int8) {
|
||||
return x;
|
||||
}
|
||||
function id(uint256 x) pure returns(uint256) {
|
||||
return x;
|
||||
}
|
||||
|
||||
contract C {
|
||||
using {id} for uint256;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7920: (145-147): Identifier not found or not unique.
|
||||
@@ -0,0 +1,10 @@
|
||||
function f(uint8 x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
function f(int8 storage x) pure returns (int) {
|
||||
return x[0];
|
||||
}
|
||||
using {f} for uint8;
|
||||
using {f} for int;
|
||||
// ----
|
||||
// DeclarationError 7920: (132-133): Identifier not found or not unique.
|
||||
@@ -0,0 +1,9 @@
|
||||
function f(uint x, uint[] y) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
function f(uint x, uint y) pure returns (int) {
|
||||
return x;
|
||||
}
|
||||
using {f} for uint;
|
||||
// ----
|
||||
// DeclarationError 7920: (138-139): Identifier not found or not unique.
|
||||
@@ -0,0 +1,11 @@
|
||||
function f(uint[] memory x) pure returns (uint) {
|
||||
return x[0];
|
||||
}
|
||||
function g(uint[] storage x) view returns (uint) {
|
||||
return x[0];
|
||||
}
|
||||
function h(uint[] calldata x) pure returns (uint) {
|
||||
return x[0];
|
||||
}
|
||||
using {f, g, h} for uint[];
|
||||
// ----
|
||||
@@ -0,0 +1,16 @@
|
||||
==== Source: A ====
|
||||
library L {
|
||||
function id(uint x) pure internal returns (uint) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
import {L as M} from "A";
|
||||
|
||||
contract C {
|
||||
using M for uint;
|
||||
function f(uint x) public pure returns (uint) {
|
||||
return x.id();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
library L {
|
||||
function id_ext(uint x) external returns(uint) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using L.id_ext for uint;
|
||||
function f(uint x) external {
|
||||
x.id_ext();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7920: (115-123): Identifier not found or not unique.
|
||||
@@ -0,0 +1,13 @@
|
||||
library L {
|
||||
function id(uint x) internal pure returns(uint) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using {L.id} for uint;
|
||||
function f(uint x) external pure {
|
||||
x.id();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,12 @@
|
||||
==== Source: A ====
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
import "A" as M;
|
||||
contract C {
|
||||
using M for uint;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (B:40-41): Library name expected. If you want to attach a function, use '{...}'.
|
||||
@@ -0,0 +1,14 @@
|
||||
==== Source: A ====
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
import {id as Id} from "A";
|
||||
|
||||
contract C {
|
||||
using { Id } for uint;
|
||||
function f(uint x) public pure returns (uint) {
|
||||
return x.Id();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
==== Source: A ====
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
import "A" as M;
|
||||
|
||||
contract C {
|
||||
using {M.id} for uint;
|
||||
function f(uint x) public pure returns (uint) {
|
||||
return x.id();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
==== Source: A ====
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
import "A" as M;
|
||||
|
||||
contract C {
|
||||
using { id } for uint;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7920: (B:43-45): Identifier not found or not unique.
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f(uint) external {
|
||||
}
|
||||
}
|
||||
interface I {
|
||||
function f(uint) external;
|
||||
}
|
||||
|
||||
contract Test {
|
||||
using C for uint;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (127-128): Library name expected. If you want to attach a function, use '{...}'.
|
||||
@@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
using {} for uint;
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (24-25): Expected identifier but got '}'
|
||||
@@ -0,0 +1,3 @@
|
||||
using {} for uint;
|
||||
// ----
|
||||
// ParserError 2314: (7-8): Expected identifier but got '}'
|
||||
@@ -0,0 +1,7 @@
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
using {id} for *;
|
||||
// ----
|
||||
// SyntaxError 8118: (59-76): The type has to be specified explicitly at file level (cannot use '*').
|
||||
@@ -0,0 +1,16 @@
|
||||
function id(uint x) pure returns (uint) {
|
||||
return x;
|
||||
}
|
||||
|
||||
function zero(uint) pure returns (uint) {
|
||||
return 0;
|
||||
}
|
||||
using {id} for uint;
|
||||
contract C {
|
||||
using {zero} for uint;
|
||||
|
||||
function g(uint z) pure external {
|
||||
z.zero();
|
||||
z.id();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
function one() pure returns(uint) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
using {one} for uint;
|
||||
// ----
|
||||
// TypeError 4731: (60-63): The function "one" does not have any parameters, and therefore cannot be bound to the type "uint256".
|
||||
@@ -0,0 +1,7 @@
|
||||
function f(uint) {}
|
||||
|
||||
contract C {
|
||||
using {f} for *;
|
||||
}
|
||||
// ----
|
||||
// SyntaxError 3349: (38-54): The type has to be specified explicitly when attaching specific functions.
|
||||
@@ -0,0 +1,3 @@
|
||||
using * for uint;
|
||||
// ----
|
||||
// ParserError 2314: (6-7): Expected identifier but got '*'
|
||||
@@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
using * for uint;
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (23-24): Expected identifier but got '*'
|
||||
@@ -0,0 +1,4 @@
|
||||
library L { }
|
||||
using L for *;
|
||||
// ----
|
||||
// SyntaxError 8118: (14-28): The type has to be specified explicitly at file level (cannot use '*').
|
||||
@@ -0,0 +1,3 @@
|
||||
library L { }
|
||||
using L for uint;
|
||||
// ----
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
using {f, g} for uint;
|
||||
|
||||
function f(uint) internal { }
|
||||
function g(uint) public { }
|
||||
}
|
||||
// ----
|
||||
// TypeError 4167: (24-25): Only file-level functions and library functions can be bound to a type in a "using" statement
|
||||
// TypeError 4167: (27-28): Only file-level functions and library functions can be bound to a type in a "using" statement
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
function() internal pure x;
|
||||
using {x} for uint;
|
||||
}
|
||||
// ----
|
||||
// TypeError 8187: (56-57): Expected function name.
|
||||
Reference in New Issue
Block a user