Skip to content

Commit

Permalink
Added a multisource test for UserDefinedValueTypes and imports
Browse files Browse the repository at this point in the history
Testing if `import {MyType} from "source";` works
  • Loading branch information
hrkrshnn committed Sep 15, 2021
1 parent 48e16ce commit 15fb427
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==== Source: A ====
type MyInt is int;
type MyAddress is address;
==== Source: B ====
import {MyInt, MyAddress as OurAddress} from "A";
contract A {
function f(int x) external view returns(MyInt) { return MyInt.wrap(x); }
function f(address x) external view returns(OurAddress) { return OurAddress.wrap(x); }
}
// ====
// compileViaYul: also
// ----
// f(int256): 5 -> 5
// f(address): 1 -> 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
==== Source: s1.sol ====
type MyInt is int;
==== Source: s2.sol ====
import "s1.sol" as M;
contract C {
function f(int x) public pure returns (M.MyInt) { return M.MyInt.wrap(x); }
function g(M.MyInt x) public pure returns (int) { return M.MyInt.unwrap(x); }
}
// ====
// compileViaYul: also
// ----
// f(int256): 5 -> 5
// g(int256): 1 -> 1
10 changes: 10 additions & 0 deletions test/libsolidity/syntaxTests/userDefinedValueType/multisource1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
==== Source: A ====
type MyInt is int;
type MyAddress is address;
==== Source: B ====
import {MyAddress as OurAddress} from "A";
contract A {
function f(int x) external view returns(MyInt) { return MyInt.wrap(x); }
}
// ----
// DeclarationError 7920: (B:100-105): Identifier not found or not unique.
10 changes: 10 additions & 0 deletions test/libsolidity/syntaxTests/userDefinedValueType/multisource2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
==== Source: A ====
type MyInt is int;
type MyAddress is address;
==== Source: B ====
import {MyAddress as OurAddress} from "A";
contract A {
function f(address x) external view returns(MyAddress) { return MyAddress.wrap(x); }
}
// ----
// DeclarationError 7920: (B:104-113): Identifier not found or not unique.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
==== Source: s1.sol ====
type MyInt is int;
==== Source: s2.sol ====
import "s1.sol" as M;
contract C {
function f(int x) public pure returns (M.MyInt) { return M.MyInt.wrap(x); }
function g(M.MyInt x) public pure returns (int) { return M.MyInt.unwrap(x); }
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
==== Source: s1.sol ====
type MyInt is int;
==== Source: s2.sol ====
import "s1.sol" as M;
contract C {
function f(int x) public pure returns (MyInt) { return MyInt.wrap(x); }
}
// ----
// DeclarationError 7920: (s2.sol:76-81): Identifier not found or not unique.

0 comments on commit 15fb427

Please sign in to comment.