mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11957 from ethereum/canonicalname-userdefinedvaluetype
Canonicalname for user defined value types
This commit is contained in:
commit
ea2386adb1
@ -612,13 +612,31 @@ bool DeclarationRegistrationHelper::visitNode(ASTNode& _node)
|
||||
|
||||
if (auto* declaration = dynamic_cast<Declaration*>(&_node))
|
||||
registerDeclaration(*declaration);
|
||||
|
||||
if (auto* annotation = dynamic_cast<TypeDeclarationAnnotation*>(&_node.annotation()))
|
||||
{
|
||||
string canonicalName = dynamic_cast<Declaration const&>(_node).name();
|
||||
solAssert(!canonicalName.empty(), "");
|
||||
|
||||
for (
|
||||
ASTNode const* scope = m_currentScope;
|
||||
scope != nullptr;
|
||||
scope = m_scopes[scope]->enclosingNode()
|
||||
)
|
||||
if (auto decl = dynamic_cast<Declaration const*>(scope))
|
||||
{
|
||||
solAssert(!decl->name().empty(), "");
|
||||
canonicalName = decl->name() + "." + canonicalName;
|
||||
}
|
||||
|
||||
annotation->canonicalName = canonicalName;
|
||||
}
|
||||
|
||||
if (dynamic_cast<ScopeOpener const*>(&_node))
|
||||
enterNewSubScope(_node);
|
||||
|
||||
if (auto* variableScope = dynamic_cast<VariableScope*>(&_node))
|
||||
m_currentFunction = variableScope;
|
||||
if (auto* annotation = dynamic_cast<TypeDeclarationAnnotation*>(&_node.annotation()))
|
||||
annotation->canonicalName = currentCanonicalName();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -668,23 +686,4 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio
|
||||
solAssert(_declaration.annotation().contract == m_currentContract, "");
|
||||
}
|
||||
|
||||
string DeclarationRegistrationHelper::currentCanonicalName() const
|
||||
{
|
||||
string ret;
|
||||
for (
|
||||
ASTNode const* scope = m_currentScope;
|
||||
scope != nullptr;
|
||||
scope = m_scopes[scope]->enclosingNode()
|
||||
)
|
||||
{
|
||||
if (auto decl = dynamic_cast<Declaration const*>(scope))
|
||||
{
|
||||
if (!ret.empty())
|
||||
ret = "." + ret;
|
||||
ret = decl->name() + ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -176,9 +176,6 @@ private:
|
||||
|
||||
static bool isOverloadedFunction(Declaration const& _declaration1, Declaration const& _declaration2);
|
||||
|
||||
/// @returns the canonical name of the current scope.
|
||||
std::string currentCanonicalName() const;
|
||||
|
||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes;
|
||||
ASTNode const* m_currentScope = nullptr;
|
||||
VariableScope* m_currentFunction = nullptr;
|
||||
|
@ -341,6 +341,11 @@ Type const* UserDefinedValueTypeDefinition::type() const
|
||||
return TypeProvider::typeType(TypeProvider::userDefinedValueType(*this));
|
||||
}
|
||||
|
||||
TypeDeclarationAnnotation& UserDefinedValueTypeDefinition::annotation() const
|
||||
{
|
||||
return initAnnotation<TypeDeclarationAnnotation>();
|
||||
}
|
||||
|
||||
Type const* StructDefinition::type() const
|
||||
{
|
||||
solAssert(annotation().recursive.has_value(), "Requested struct type before DeclarationTypeChecker.");
|
||||
|
@ -750,6 +750,8 @@ public:
|
||||
|
||||
Type const* type() const override;
|
||||
|
||||
TypeDeclarationAnnotation& annotation() const override;
|
||||
|
||||
TypeName const* underlyingType() const { return m_underlyingType.get(); }
|
||||
bool isVisibleViaContractTypeAccess() const override { return true; }
|
||||
|
||||
|
@ -2555,7 +2555,7 @@ bool UserDefinedValueType::operator==(Type const& _other) const
|
||||
|
||||
string UserDefinedValueType::toString(bool /* _short */) const
|
||||
{
|
||||
return "user defined type " + definition().name();
|
||||
return "user defined type " + *definition().annotation().canonicalName;
|
||||
}
|
||||
|
||||
vector<tuple<string, Type const*>> UserDefinedValueType::makeStackItems() const
|
||||
|
@ -36,7 +36,7 @@ contract C {
|
||||
// "outputs":
|
||||
// [
|
||||
// {
|
||||
// "internalType": "user defined type MyAddress",
|
||||
// "internalType": "user defined type C.MyAddress",
|
||||
// "name": "",
|
||||
// "type": "address"
|
||||
// }
|
||||
@ -64,7 +64,7 @@ contract C {
|
||||
// "outputs":
|
||||
// [
|
||||
// {
|
||||
// "internalType": "user defined type MyBytes32",
|
||||
// "internalType": "user defined type C.MyBytes32",
|
||||
// "name": "",
|
||||
// "type": "bytes32"
|
||||
// }
|
||||
@ -92,7 +92,7 @@ contract C {
|
||||
// "outputs":
|
||||
// [
|
||||
// {
|
||||
// "internalType": "user defined type MyUInt8",
|
||||
// "internalType": "user defined type C.MyUInt8",
|
||||
// "name": "",
|
||||
// "type": "uint8"
|
||||
// }
|
||||
@ -104,7 +104,7 @@ contract C {
|
||||
// "inputs":
|
||||
// [
|
||||
// {
|
||||
// "internalType": "user defined type MyAddress",
|
||||
// "internalType": "user defined type C.MyAddress",
|
||||
// "name": "a",
|
||||
// "type": "address"
|
||||
// }
|
||||
@ -132,7 +132,7 @@ contract C {
|
||||
// "inputs":
|
||||
// [
|
||||
// {
|
||||
// "internalType": "user defined type MyBytes32",
|
||||
// "internalType": "user defined type C.MyBytes32",
|
||||
// "name": "a",
|
||||
// "type": "bytes32"
|
||||
// }
|
||||
@ -160,7 +160,7 @@ contract C {
|
||||
// "inputs":
|
||||
// [
|
||||
// {
|
||||
// "internalType": "user defined type MyUInt8",
|
||||
// "internalType": "user defined type C.MyUInt8",
|
||||
// "name": "a",
|
||||
// "type": "uint8"
|
||||
// }
|
||||
|
@ -269,7 +269,7 @@
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_userDefinedValueType$_MyAddress_$18_$_t_userDefinedValueType$_MyUInt_$20_$",
|
||||
"typeString": "mapping(user defined type MyAddress => user defined type MyUInt)"
|
||||
"typeString": "mapping(user defined type C.MyAddress => user defined type C.MyUInt)"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
@ -291,7 +291,7 @@
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_userDefinedValueType$_MyAddress_$18",
|
||||
"typeString": "user defined type MyAddress"
|
||||
"typeString": "user defined type C.MyAddress"
|
||||
}
|
||||
},
|
||||
"nodeType": "Mapping",
|
||||
@ -299,7 +299,7 @@
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_mapping$_t_userDefinedValueType$_MyAddress_$18_$_t_userDefinedValueType$_MyUInt_$20_$",
|
||||
"typeString": "mapping(user defined type MyAddress => user defined type MyUInt)"
|
||||
"typeString": "mapping(user defined type C.MyAddress => user defined type C.MyUInt)"
|
||||
},
|
||||
"valueType":
|
||||
{
|
||||
@ -318,7 +318,7 @@
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_userDefinedValueType$_MyUInt_$20",
|
||||
"typeString": "user defined type MyUInt"
|
||||
"typeString": "user defined type C.MyUInt"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5,4 +5,4 @@ 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.
|
||||
// TypeError 7407: (86-103): Type user defined type L.T is not implicitly convertible to expected type user defined type C.T.
|
||||
|
Loading…
Reference in New Issue
Block a user