Skip to content

Commit

Permalink
Allow accessing user defined value type members via contract name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekpyron committed Sep 14, 2021
1 parent 94daad7 commit be29ef7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ class UserDefinedValueTypeDefinition: public Declaration
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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));
}
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit be29ef7

Please sign in to comment.