mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #12836 from ethereum/fixUsingGlobal
Fix using global with libraries.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using L for I;
|
||||
interface I { function f() external pure returns (uint); }
|
||||
library L {
|
||||
function execute(I i) internal pure returns (uint) {
|
||||
return i.f();
|
||||
}
|
||||
}
|
||||
contract C is I {
|
||||
function x() public view returns (uint) {
|
||||
I i = this;
|
||||
return i.execute();
|
||||
}
|
||||
function f() public pure returns (uint) { return 7; }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// x() -> 7
|
||||
@@ -0,0 +1,38 @@
|
||||
==== Source: A ====
|
||||
enum E {A, B}
|
||||
struct S { uint x; }
|
||||
type T is uint;
|
||||
using L for E global;
|
||||
using L for S global;
|
||||
using L for T global;
|
||||
library L {
|
||||
function f(E e) internal pure returns (uint) {
|
||||
return uint(e);
|
||||
}
|
||||
function f(S memory s) internal pure returns (uint) {
|
||||
return s.x;
|
||||
}
|
||||
function f(T t) internal pure returns (uint) {
|
||||
return T.unwrap(t);
|
||||
}
|
||||
}
|
||||
|
||||
==== Source: B ====
|
||||
contract C {
|
||||
function f() public pure returns (uint a, uint b, uint c) {
|
||||
E e = E.B;
|
||||
a = e.f();
|
||||
S memory s;
|
||||
s.x = 7;
|
||||
b = s.f();
|
||||
T t = T.wrap(9);
|
||||
c = t.f();
|
||||
}
|
||||
}
|
||||
|
||||
import {E, S, T} from "A";
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 1, 7, 9
|
||||
@@ -4,4 +4,3 @@ contract C {
|
||||
function f(uint) pure{}
|
||||
// ----
|
||||
// SyntaxError 3367: (17-43): "global" can only be used at file level.
|
||||
// TypeError 8841: (17-43): Can only use "global" with user-defined types.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using L for uint global;
|
||||
using L for uint[] global;
|
||||
using L for function() returns (uint) global;
|
||||
library L {
|
||||
}
|
||||
// ----
|
||||
// TypeError 8841: (0-24): Can only use "global" with user-defined types.
|
||||
// TypeError 8841: (25-51): Can only use "global" with user-defined types.
|
||||
// TypeError 8841: (52-97): Can only use "global" with user-defined types.
|
||||
@@ -0,0 +1,6 @@
|
||||
using L for L.S global;
|
||||
library L {
|
||||
struct S { uint x; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 4117: (0-23): Can only use "global" with types defined in the same source unit at file level.
|
||||
@@ -0,0 +1,6 @@
|
||||
interface I {}
|
||||
using L for I global;
|
||||
library L {
|
||||
}
|
||||
// ----
|
||||
// TypeError 8841: (15-36): Can only use "global" with user-defined types.
|
||||
@@ -0,0 +1,8 @@
|
||||
==== Source: A ====
|
||||
struct S { uint x; }
|
||||
==== Source: B ====
|
||||
library L {}
|
||||
using L for S global;
|
||||
import {S} from "A";
|
||||
// ----
|
||||
// TypeError 4117: (B:13-34): Can only use "global" with types defined in the same source unit at file level.
|
||||
@@ -0,0 +1,5 @@
|
||||
using L for * global;
|
||||
library L {}
|
||||
// ----
|
||||
// SyntaxError 8118: (0-21): The type has to be specified explicitly at file level (cannot use '*').
|
||||
// SyntaxError 2854: (0-21): Can only globally bind functions to specific types.
|
||||
@@ -0,0 +1,5 @@
|
||||
using {f} for * global;
|
||||
function f(uint) pure{}
|
||||
// ----
|
||||
// SyntaxError 8118: (0-23): The type has to be specified explicitly at file level (cannot use '*').
|
||||
// SyntaxError 2854: (0-23): Can only globally bind functions to specific types.
|
||||
Reference in New Issue
Block a user