Forbid private library functions to be attached outside their declaration scope

This commit is contained in:
Matheus Aguiar
2023-01-17 16:27:35 -03:00
parent 229fcc9fce
commit 7779b6f352
5 changed files with 53 additions and 0 deletions
@@ -0,0 +1,10 @@
library L {
using {L.privateFunction} for uint;
function privateFunction(uint x) private pure returns (uint) { return x + 1; }
function f() public pure returns (uint) {
uint x = 1;
return x.privateFunction();
}
}
// ----
// f() -> 2
@@ -0,0 +1,5 @@
library L {
using {L.privateFunction} for uint;
function privateFunction(uint) private pure {}
}
// ----
@@ -0,0 +1,12 @@
library L {
function privateFunction(uint) private pure {}
}
using {L.privateFunction} for uint;
contract C {
using {L.privateFunction} for uint;
}
// ----
// TypeError 6772: (73-90): Function "L.privateFunction" is private and therefore cannot be attached to a type outside of the library where it is defined.
// TypeError 6772: (127-144): Function "L.privateFunction" is private and therefore cannot be attached to a type outside of the library where it is defined.