From 15fb427a998314520f80ec56309d10de5ea34165 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Tue, 14 Sep 2021 16:02:42 +0200 Subject: [PATCH] Added a multisource test for UserDefinedValueTypes and imports Testing if `import {MyType} from "source";` works --- .../userDefinedValueType/multisource.sol | 14 ++++++++++++++ .../userDefinedValueType/multisource_module.sol | 13 +++++++++++++ .../userDefinedValueType/multisource1.sol | 10 ++++++++++ .../userDefinedValueType/multisource2.sol | 10 ++++++++++ .../userDefinedValueType/multisource3.sol | 9 +++++++++ .../userDefinedValueType/multisource4.sol | 9 +++++++++ 6 files changed, 65 insertions(+) create mode 100644 test/libsolidity/semanticTests/userDefinedValueType/multisource.sol create mode 100644 test/libsolidity/semanticTests/userDefinedValueType/multisource_module.sol create mode 100644 test/libsolidity/syntaxTests/userDefinedValueType/multisource1.sol create mode 100644 test/libsolidity/syntaxTests/userDefinedValueType/multisource2.sol create mode 100644 test/libsolidity/syntaxTests/userDefinedValueType/multisource3.sol create mode 100644 test/libsolidity/syntaxTests/userDefinedValueType/multisource4.sol diff --git a/test/libsolidity/semanticTests/userDefinedValueType/multisource.sol b/test/libsolidity/semanticTests/userDefinedValueType/multisource.sol new file mode 100644 index 000000000..67069157c --- /dev/null +++ b/test/libsolidity/semanticTests/userDefinedValueType/multisource.sol @@ -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 diff --git a/test/libsolidity/semanticTests/userDefinedValueType/multisource_module.sol b/test/libsolidity/semanticTests/userDefinedValueType/multisource_module.sol new file mode 100644 index 000000000..2d2833059 --- /dev/null +++ b/test/libsolidity/semanticTests/userDefinedValueType/multisource_module.sol @@ -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 diff --git a/test/libsolidity/syntaxTests/userDefinedValueType/multisource1.sol b/test/libsolidity/syntaxTests/userDefinedValueType/multisource1.sol new file mode 100644 index 000000000..b6a7b5bcc --- /dev/null +++ b/test/libsolidity/syntaxTests/userDefinedValueType/multisource1.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/userDefinedValueType/multisource2.sol b/test/libsolidity/syntaxTests/userDefinedValueType/multisource2.sol new file mode 100644 index 000000000..a0e7f9ec0 --- /dev/null +++ b/test/libsolidity/syntaxTests/userDefinedValueType/multisource2.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/userDefinedValueType/multisource3.sol b/test/libsolidity/syntaxTests/userDefinedValueType/multisource3.sol new file mode 100644 index 000000000..ed2cbde28 --- /dev/null +++ b/test/libsolidity/syntaxTests/userDefinedValueType/multisource3.sol @@ -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); } +} +// ---- diff --git a/test/libsolidity/syntaxTests/userDefinedValueType/multisource4.sol b/test/libsolidity/syntaxTests/userDefinedValueType/multisource4.sol new file mode 100644 index 000000000..92a1e54f1 --- /dev/null +++ b/test/libsolidity/syntaxTests/userDefinedValueType/multisource4.sol @@ -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.