mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow UserDefinedValueType.uwrap (and wrap) as RHS of constant decl
Needed to make `MyType.unwrap` and `MyType.unwrap` as pure in the process. This change affected some existing tests ("statement has no effect").
This commit is contained in:
parent
dea1b9ec79
commit
a1d4d0125d
@ -2916,7 +2916,10 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
|
|||||||
// TODO some members might be pure, but for example `address(0x123).balance` is not pure
|
// TODO some members might be pure, but for example `address(0x123).balance` is not pure
|
||||||
// although every subexpression is, so leaving this limited for now.
|
// although every subexpression is, so leaving this limited for now.
|
||||||
if (auto tt = dynamic_cast<TypeType const*>(exprType))
|
if (auto tt = dynamic_cast<TypeType const*>(exprType))
|
||||||
if (tt->actualType()->category() == Type::Category::Enum)
|
if (
|
||||||
|
tt->actualType()->category() == Type::Category::Enum ||
|
||||||
|
tt->actualType()->category() == Type::Category::UserDefinedValueType
|
||||||
|
)
|
||||||
annotation.isPure = true;
|
annotation.isPure = true;
|
||||||
if (
|
if (
|
||||||
auto const* functionType = dynamic_cast<FunctionType const*>(exprType);
|
auto const* functionType = dynamic_cast<FunctionType const*>(exprType);
|
||||||
|
@ -3499,7 +3499,9 @@ bool FunctionType::isPure() const
|
|||||||
m_kind == Kind::ABIEncodeWithSelector ||
|
m_kind == Kind::ABIEncodeWithSelector ||
|
||||||
m_kind == Kind::ABIEncodeWithSignature ||
|
m_kind == Kind::ABIEncodeWithSignature ||
|
||||||
m_kind == Kind::ABIDecode ||
|
m_kind == Kind::ABIDecode ||
|
||||||
m_kind == Kind::MetaType;
|
m_kind == Kind::MetaType ||
|
||||||
|
m_kind == Kind::Wrap ||
|
||||||
|
m_kind == Kind::Unwrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypePointers FunctionType::parseElementaryTypeVector(strings const& _types)
|
TypePointers FunctionType::parseElementaryTypeVector(strings const& _types)
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
type T is int224;
|
||||||
|
pragma solidity >= 0.0.0;
|
||||||
|
contract C {
|
||||||
|
T constant public s = T.wrap(int224(165521356710917456517261742455526507355687727119203895813322792776));
|
||||||
|
T constant public t = s;
|
||||||
|
int224 constant public u = T.unwrap(t);
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// s() -> 165521356710917456517261742455526507355687727119203895813322792776
|
||||||
|
// t() -> 165521356710917456517261742455526507355687727119203895813322792776
|
||||||
|
// u() -> 165521356710917456517261742455526507355687727119203895813322792776
|
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
type MyInt is int;
|
||||||
|
MyInt constant mi = MyInt.wrap(5);
|
||||||
|
// This is currently unsupported.
|
||||||
|
uint[MyInt.unwrap(mi)] arr;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 5462: (122-138): Invalid array length, expected integer literal or constant expression.
|
@ -6,3 +6,5 @@ function f() pure {
|
|||||||
MyAddress.wrap(address(5));
|
MyAddress.wrap(address(5));
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// Warning 6133: (73-87): Statement has no effect.
|
||||||
|
// Warning 6133: (93-119): Statement has no effect.
|
||||||
|
@ -7,3 +7,6 @@ function f() pure {
|
|||||||
MyUInt8.wrap(50);
|
MyUInt8.wrap(50);
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// Warning 6133: (75-101): Statement has no effect.
|
||||||
|
// Warning 6133: (107-122): Statement has no effect.
|
||||||
|
// Warning 6133: (128-144): Statement has no effect.
|
||||||
|
Loading…
Reference in New Issue
Block a user