Allow accessing user defined value type members via contract name.

This commit is contained in:
Daniel Kirchner 2021-09-14 16:13:36 +02:00
parent 94daad7c3d
commit be29ef70a7
4 changed files with 42 additions and 0 deletions

View File

@ -751,6 +751,7 @@ public:
Type const* type() const override;
TypeName const* underlyingType() const { return m_underlyingType.get(); }
bool isVisibleViaContractTypeAccess() const override { return true; }
private:
/// The name of the underlying type

View File

@ -0,0 +1,24 @@
contract C {
type T is uint;
}
contract D {
function f(C.T x) public pure returns(uint) {
return C.T.unwrap(x);
}
function g(uint x) public pure returns(C.T) {
return C.T.wrap(x);
}
function h(uint x) public pure returns(uint) {
return f(g(x));
}
function i(C.T x) public pure returns(C.T) {
return g(f(x));
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 0x42 -> 0x42
// g(uint256): 0x42 -> 0x42
// h(uint256): 0x42 -> 0x42
// i(uint256): 0x42 -> 0x42

View File

@ -0,0 +1,9 @@
contract C { type T is uint; }
library L { type T is uint; }
interface I { type T is uint; }
contract D
{
C.T x = C.T.wrap(uint(1));
L.T y = L.T.wrap(uint(1));
I.T z = I.T.wrap(uint(1));
}

View File

@ -0,0 +1,8 @@
contract C { type T is uint; }
library L { type T is uint; }
contract D
{
C.T x = L.T.wrap(uint(1));
}
// ----
// TypeError 7407: (86-103): Type user defined type T is not implicitly convertible to expected type user defined type T.