mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow library external functions to be bound with using for
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function f() public pure {
|
||||
uint x;
|
||||
externalFunction(x);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7576: (120-136): Undeclared identifier. "externalFunction" is not (or not yet) visible at this point.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
using {this.contractFunction} for uint;
|
||||
|
||||
function contractFunction(uint) external view {}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 9589: (24-45): Identifier is not a function name or not unique.
|
||||
@@ -9,4 +9,4 @@ contract C {
|
||||
using {id} for uint256;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7920: (145-147): Identifier not found or not unique.
|
||||
// DeclarationError 9589: (145-147): Identifier is not a function name or not unique.
|
||||
|
||||
@@ -7,4 +7,4 @@ function f(int8 storage x) pure returns (int) {
|
||||
using {f} for uint8;
|
||||
using {f} for int;
|
||||
// ----
|
||||
// DeclarationError 7920: (132-133): Identifier not found or not unique.
|
||||
// DeclarationError 9589: (132-133): Identifier is not a function name or not unique.
|
||||
|
||||
@@ -6,4 +6,4 @@ function f(uint x, uint y) pure returns (int) {
|
||||
}
|
||||
using {f} for uint;
|
||||
// ----
|
||||
// DeclarationError 7920: (138-139): Identifier not found or not unique.
|
||||
// DeclarationError 9589: (138-139): Identifier is not a function name or not unique.
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function baseFunction(uint) public pure {}
|
||||
}
|
||||
|
||||
contract D is C {
|
||||
using {super.baseFunction} for uint;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 9589: (92-110): Identifier is not a function name or not unique.
|
||||
@@ -0,0 +1,11 @@
|
||||
function f(uint x) pure { }
|
||||
|
||||
using f for uint;
|
||||
|
||||
contract C {
|
||||
function g(uint x) public pure {
|
||||
x.f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (35-36): Library name expected. If you want to attach a function, use '{...}'.
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
function f(uint x) pure { }
|
||||
|
||||
contract C {
|
||||
using f for uint;
|
||||
function g(uint x) public pure {
|
||||
x.f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4357: (52-53): Library name expected. If you want to attach a function, use '{...}'.
|
||||
@@ -0,0 +1,7 @@
|
||||
interface I {
|
||||
function g() external pure;
|
||||
}
|
||||
|
||||
using {I.g} for uint;
|
||||
// ----
|
||||
// TypeError 4167: (56-59): Only file-level functions and library functions can be attached to a type in a "using" statement
|
||||
@@ -0,0 +1,9 @@
|
||||
interface I {
|
||||
function g() external pure;
|
||||
}
|
||||
|
||||
contract C {
|
||||
using {I.g} for uint;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4167: (73-76): Only file-level functions and library functions can be attached to a type in a "using" statement
|
||||
@@ -0,0 +1,17 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
}
|
||||
|
||||
using L for uint;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,19 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
}
|
||||
|
||||
using {L.externalFunction} for uint;
|
||||
using {L.publicFunction} for uint;
|
||||
using {L.internalFunction} for uint;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using {L.externalFunction, L.publicFunction, L.internalFunction} for uint;
|
||||
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 6700: (299-319): Libraries cannot call their own functions externally.
|
||||
// TypeError 6700: (329-347): Libraries cannot call their own functions externally.
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
}
|
||||
|
||||
using {L.externalFunction, L.publicFunction, L.internalFunction} for uint;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using {L.externalFunction, L.publicFunction, L.internalFunction} for uint;
|
||||
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,19 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using {L.externalFunction} for uint;
|
||||
using {L.publicFunction} for uint;
|
||||
using {L.internalFunction} for uint;
|
||||
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,17 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using L for uint;
|
||||
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -11,4 +11,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7920: (115-123): Identifier not found or not unique.
|
||||
// TypeError 4357: (115-123): Library name expected. If you want to attach a function, use '{...}'.
|
||||
|
||||
@@ -10,4 +10,4 @@ contract C {
|
||||
using { id } for uint;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7920: (B:43-45): Identifier not found or not unique.
|
||||
// DeclarationError 9589: (B:43-45): Identifier is not a function name or not unique.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
contract A {
|
||||
uint public data;
|
||||
}
|
||||
|
||||
contract C {
|
||||
A a = new A();
|
||||
|
||||
using {a.data} for uint;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 9589: (82-88): Identifier is not a function name or not unique.
|
||||
@@ -0,0 +1,3 @@
|
||||
using L for uint;
|
||||
// ----
|
||||
// DeclarationError 9589: (6-7): Identifier is not a library name.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
library L {
|
||||
function externalFunction(uint) external pure {}
|
||||
function publicFunction(uint) public pure {}
|
||||
function internalFunction(uint) internal pure {}
|
||||
function privateFunction(uint) private pure {}
|
||||
|
||||
using {externalFunction, publicFunction, internalFunction, privateFunction} for uint;
|
||||
|
||||
function f() public pure {
|
||||
uint x;
|
||||
x.externalFunction();
|
||||
x.publicFunction();
|
||||
x.internalFunction();
|
||||
x.privateFunction();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 6700: (365-385): Libraries cannot call their own functions externally.
|
||||
// TypeError 6700: (395-413): Libraries cannot call their own functions externally.
|
||||
Reference in New Issue
Block a user