diff --git a/Changelog.md b/Changelog.md index 828d86ed4..a44d460e7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ Compiler Features: Bugfixes: + * AST export: Export `immutable` property in the field `mutability`. * SMTChecker: Fix internal error in the CHC engine when calling inherited functions internally. diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index b1328d008..c0f7e6dc9 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -854,7 +854,17 @@ class VariableDeclaration: public Declaration { public: enum Location { Unspecified, Storage, Memory, CallData }; - enum class Constantness { Mutable, Immutable, Constant }; + enum class Mutability { Mutable, Immutable, Constant }; + static std::string mutabilityToString(Mutability _mutability) + { + switch (_mutability) + { + case Mutability::Mutable: return "mutable"; + case Mutability::Immutable: return "immutable"; + case Mutability::Constant: return "constant"; + } + return {}; + } VariableDeclaration( int64_t _id, @@ -865,7 +875,7 @@ public: Visibility _visibility, bool _isStateVar = false, bool _isIndexed = false, - Constantness _constantness = Constantness::Mutable, + Mutability _mutability = Mutability::Mutable, ASTPointer const& _overrides = nullptr, Location _referenceLocation = Location::Unspecified ): @@ -874,7 +884,7 @@ public: m_value(_value), m_isStateVariable(_isStateVar), m_isIndexed(_isIndexed), - m_constantness(_constantness), + m_mutability(_mutability), m_overrides(_overrides), m_location(_referenceLocation) {} @@ -918,8 +928,9 @@ public: bool hasReferenceOrMappingType() const; bool isStateVariable() const { return m_isStateVariable; } bool isIndexed() const { return m_isIndexed; } - bool isConstant() const { return m_constantness == Constantness::Constant; } - bool immutable() const { return m_constantness == Constantness::Immutable; } + Mutability mutability() const { return m_mutability; } + bool isConstant() const { return m_mutability == Mutability::Constant; } + bool immutable() const { return m_mutability == Mutability::Immutable; } ASTPointer const& overrides() const { return m_overrides; } Location referenceLocation() const { return m_location; } /// @returns a set of allowed storage locations for the variable. @@ -947,7 +958,7 @@ private: bool m_isStateVariable = false; ///< Whether or not this is a contract state variable bool m_isIndexed = false; ///< Whether this is an indexed variable (used by events). /// Whether the variable is "constant", "immutable" or non-marked (mutable). - Constantness m_constantness = Constantness::Mutable; + Mutability m_mutability = Mutability::Mutable; ASTPointer m_overrides; ///< Contains the override specifier node Location m_location = Location::Unspecified; ///< Location of the variable if it is of reference type. }; diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index ed3c6fff9..81802907f 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -378,6 +378,7 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node) make_pair("name", _node.name()), make_pair("typeName", toJsonOrNull(_node.typeName())), make_pair("constant", _node.isConstant()), + make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())), make_pair("stateVariable", _node.isStateVariable()), make_pair("storageLocation", location(_node.referenceLocation())), make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), diff --git a/libsolidity/ast/ASTJsonImporter.cpp b/libsolidity/ast/ASTJsonImporter.cpp index 441fd66d1..7d388877b 100644 --- a/libsolidity/ast/ASTJsonImporter.cpp +++ b/libsolidity/ast/ASTJsonImporter.cpp @@ -411,11 +411,24 @@ ASTPointer ASTJsonImporter::createVariableDeclaration(Json: { astAssert(_node["name"].isString(), "Expected 'name' to be a string!"); - VariableDeclaration::Constantness constantness{}; - if (memberAsBool(_node, "constant")) - constantness = VariableDeclaration::Constantness::Constant; + VariableDeclaration::Mutability mutability{}; + astAssert(member(_node, "mutability").isString(), "'mutability' expected to be string."); + string const mutabilityStr = member(_node, "mutability").asString(); + if (mutabilityStr == "constant") + { + mutability = VariableDeclaration::Mutability::Constant; + astAssert(memberAsBool(_node, "constant"), ""); + } else - constantness = VariableDeclaration::Constantness::Mutable; + { + astAssert(!memberAsBool(_node, "constant"), ""); + if (mutabilityStr == "mutable") + mutability = VariableDeclaration::Mutability::Mutable; + else if (mutabilityStr == "immutable") + mutability = VariableDeclaration::Mutability::Immutable; + else + astAssert(false, ""); + } return createASTNode( _node, @@ -425,7 +438,7 @@ ASTPointer ASTJsonImporter::createVariableDeclaration(Json: visibility(_node), memberAsBool(_node, "stateVariable"), _node.isMember("indexed") ? memberAsBool(_node, "indexed") : false, - constantness, + mutability, _node["overrides"].isNull() ? nullptr : createOverrideSpecifier(member(_node, "overrides")), location(_node) ); diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 2f23c8c22..befd3c696 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -695,7 +695,7 @@ ASTPointer Parser::parseVariableDeclaration( ); bool isIndexed = false; - VariableDeclaration::Constantness constantness = VariableDeclaration::Constantness::Mutable; + VariableDeclaration::Mutability mutability = VariableDeclaration::Mutability::Mutable; ASTPointer overrides = nullptr; Visibility visibility(Visibility::Default); VariableDeclaration::Location location = VariableDeclaration::Location::Unspecified; @@ -732,15 +732,15 @@ ASTPointer Parser::parseVariableDeclaration( isIndexed = true; else if (token == Token::Constant || token == Token::Immutable) { - if (constantness != VariableDeclaration::Constantness::Mutable) + if (mutability != VariableDeclaration::Mutability::Mutable) parserError( - string("Constantness already set to ") + - (constantness == VariableDeclaration::Constantness::Constant ? "\"constant\"" : "\"immutable\"") + string("Mutability already set to ") + + (mutability == VariableDeclaration::Mutability::Constant ? "\"constant\"" : "\"immutable\"") ); else if (token == Token::Constant) - constantness = VariableDeclaration::Constantness::Constant; + mutability = VariableDeclaration::Mutability::Constant; else if (token == Token::Immutable) - constantness = VariableDeclaration::Constantness::Immutable; + mutability = VariableDeclaration::Mutability::Immutable; } else if (_options.allowLocationSpecifier && TokenTraits::isLocationSpecifier(token)) { @@ -800,7 +800,7 @@ ASTPointer Parser::parseVariableDeclaration( visibility, _options.isStateVariable, isIndexed, - constantness, + mutability, overrides, location ); diff --git a/test/cmdlineTests/recovery_ast_constructor/output b/test/cmdlineTests/recovery_ast_constructor/output index e7dd79791..f2cc2ccf8 100644 --- a/test/cmdlineTests/recovery_ast_constructor/output +++ b/test/cmdlineTests/recovery_ast_constructor/output @@ -160,6 +160,7 @@ JSON AST: "attributes": { "constant": false, + "mutability": "mutable", "name": "", "overrides": null, "scope": 17, diff --git a/test/libsolidity/ASTJSON/address_payable.json b/test/libsolidity/ASTJSON/address_payable.json index fbf2f3e59..ef965ac79 100644 --- a/test/libsolidity/ASTJSON/address_payable.json +++ b/test/libsolidity/ASTJSON/address_payable.json @@ -31,6 +31,7 @@ "constant": false, "functionSelector": "97682884", "id": 4, + "mutability": "mutable", "name": "m", "nodeType": "VariableDeclaration", "overrides": null, @@ -100,6 +101,7 @@ { "constant": false, "id": 12, + "mutability": "mutable", "name": "a", "nodeType": "VariableDeclaration", "overrides": null, @@ -241,6 +243,7 @@ { "constant": false, "id": 22, + "mutability": "mutable", "name": "c", "nodeType": "VariableDeclaration", "overrides": null, @@ -507,6 +510,7 @@ { "constant": false, "id": 6, + "mutability": "mutable", "name": "arg", "nodeType": "VariableDeclaration", "overrides": null, @@ -547,6 +551,7 @@ { "constant": false, "id": 9, + "mutability": "mutable", "name": "r", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/address_payable_legacy.json b/test/libsolidity/ASTJSON/address_payable_legacy.json index c45e75c4a..dd33e6408 100644 --- a/test/libsolidity/ASTJSON/address_payable_legacy.json +++ b/test/libsolidity/ASTJSON/address_payable_legacy.json @@ -41,6 +41,7 @@ { "constant": false, "functionSelector": "97682884", + "mutability": "mutable", "name": "m", "overrides": null, "scope": 39, @@ -118,6 +119,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "arg", "overrides": null, "scope": 38, @@ -157,6 +159,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "r", "overrides": null, "scope": 38, @@ -206,6 +209,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "a", "overrides": null, "scope": 37, @@ -359,6 +363,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "c", "overrides": null, "scope": 37, diff --git a/test/libsolidity/ASTJSON/array_type_name.json b/test/libsolidity/ASTJSON/array_type_name.json index 6fea9f532..e97518cb8 100644 --- a/test/libsolidity/ASTJSON/array_type_name.json +++ b/test/libsolidity/ASTJSON/array_type_name.json @@ -30,6 +30,7 @@ { "constant": false, "id": 3, + "mutability": "mutable", "name": "i", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/array_type_name_legacy.json b/test/libsolidity/ASTJSON/array_type_name_legacy.json index a706c2f3a..37175bb37 100644 --- a/test/libsolidity/ASTJSON/array_type_name_legacy.json +++ b/test/libsolidity/ASTJSON/array_type_name_legacy.json @@ -40,6 +40,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "i", "overrides": null, "scope": 4, diff --git a/test/libsolidity/ASTJSON/assembly/nested_functions.json b/test/libsolidity/ASTJSON/assembly/nested_functions.json index b990a963f..73022e005 100644 --- a/test/libsolidity/ASTJSON/assembly/nested_functions.json +++ b/test/libsolidity/ASTJSON/assembly/nested_functions.json @@ -121,6 +121,7 @@ { "constant": false, "id": 3, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/assembly/nested_functions_legacy.json b/test/libsolidity/ASTJSON/assembly/nested_functions_legacy.json index abaf60fb7..e2b4926f7 100644 --- a/test/libsolidity/ASTJSON/assembly/nested_functions_legacy.json +++ b/test/libsolidity/ASTJSON/assembly/nested_functions_legacy.json @@ -77,6 +77,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 7, diff --git a/test/libsolidity/ASTJSON/assembly/slot_offset.json b/test/libsolidity/ASTJSON/assembly/slot_offset.json index 68a7603ea..75c22243c 100644 --- a/test/libsolidity/ASTJSON/assembly/slot_offset.json +++ b/test/libsolidity/ASTJSON/assembly/slot_offset.json @@ -35,6 +35,7 @@ { "constant": false, "id": 2, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, @@ -72,6 +73,7 @@ { "constant": false, "id": 5, + "mutability": "mutable", "name": "s", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/assembly/slot_offset_legacy.json b/test/libsolidity/ASTJSON/assembly/slot_offset_legacy.json index 800e5b627..083f8dd52 100644 --- a/test/libsolidity/ASTJSON/assembly/slot_offset_legacy.json +++ b/test/libsolidity/ASTJSON/assembly/slot_offset_legacy.json @@ -50,6 +50,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 3, @@ -85,6 +86,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "s", "overrides": null, "scope": 11, diff --git a/test/libsolidity/ASTJSON/assembly/var_access.json b/test/libsolidity/ASTJSON/assembly/var_access.json index 1e66ef6b3..0ef180ced 100644 --- a/test/libsolidity/ASTJSON/assembly/var_access.json +++ b/test/libsolidity/ASTJSON/assembly/var_access.json @@ -45,6 +45,7 @@ { "constant": false, "id": 4, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/assembly/var_access_legacy.json b/test/libsolidity/ASTJSON/assembly/var_access_legacy.json index 0442ace76..21cda71e8 100644 --- a/test/libsolidity/ASTJSON/assembly/var_access_legacy.json +++ b/test/libsolidity/ASTJSON/assembly/var_access_legacy.json @@ -101,6 +101,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 7, diff --git a/test/libsolidity/ASTJSON/function_type.json b/test/libsolidity/ASTJSON/function_type.json index 33ba4b22a..e1e83a316 100644 --- a/test/libsolidity/ASTJSON/function_type.json +++ b/test/libsolidity/ASTJSON/function_type.json @@ -53,6 +53,7 @@ { "constant": false, "id": 6, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, @@ -85,6 +86,7 @@ { "constant": false, "id": 3, + "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "overrides": null, @@ -139,6 +141,7 @@ { "constant": false, "id": 13, + "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "overrides": null, @@ -171,6 +174,7 @@ { "constant": false, "id": 10, + "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/function_type_legacy.json b/test/libsolidity/ASTJSON/function_type_legacy.json index 8fa58f9c9..e86eb16a6 100644 --- a/test/libsolidity/ASTJSON/function_type_legacy.json +++ b/test/libsolidity/ASTJSON/function_type_legacy.json @@ -64,6 +64,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 16, @@ -104,6 +105,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "", "overrides": null, "scope": 5, @@ -157,6 +159,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "", "overrides": null, "scope": 16, @@ -197,6 +200,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "", "overrides": null, "scope": 12, diff --git a/test/libsolidity/ASTJSON/global_struct.json b/test/libsolidity/ASTJSON/global_struct.json index 6eaaee8d9..64cf62a53 100644 --- a/test/libsolidity/ASTJSON/global_struct.json +++ b/test/libsolidity/ASTJSON/global_struct.json @@ -19,6 +19,7 @@ { "constant": false, "id": 2, + "mutability": "mutable", "name": "a", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/global_struct_legacy.json b/test/libsolidity/ASTJSON/global_struct_legacy.json index fd68cee57..ef0f71c37 100644 --- a/test/libsolidity/ASTJSON/global_struct_legacy.json +++ b/test/libsolidity/ASTJSON/global_struct_legacy.json @@ -26,6 +26,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "a", "overrides": null, "scope": 3, diff --git a/test/libsolidity/ASTJSON/long_type_name_binary_operation.json b/test/libsolidity/ASTJSON/long_type_name_binary_operation.json index e6d8b4d20..6e025f5f9 100644 --- a/test/libsolidity/ASTJSON/long_type_name_binary_operation.json +++ b/test/libsolidity/ASTJSON/long_type_name_binary_operation.json @@ -45,6 +45,7 @@ { "constant": false, "id": 4, + "mutability": "mutable", "name": "a", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/long_type_name_binary_operation_legacy.json b/test/libsolidity/ASTJSON/long_type_name_binary_operation_legacy.json index 977f783dd..6ad38d194 100644 --- a/test/libsolidity/ASTJSON/long_type_name_binary_operation_legacy.json +++ b/test/libsolidity/ASTJSON/long_type_name_binary_operation_legacy.json @@ -100,6 +100,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "a", "overrides": null, "scope": 9, diff --git a/test/libsolidity/ASTJSON/long_type_name_identifier.json b/test/libsolidity/ASTJSON/long_type_name_identifier.json index 5c8951d29..eddeacd04 100644 --- a/test/libsolidity/ASTJSON/long_type_name_identifier.json +++ b/test/libsolidity/ASTJSON/long_type_name_identifier.json @@ -30,6 +30,7 @@ { "constant": false, "id": 3, + "mutability": "mutable", "name": "a", "nodeType": "VariableDeclaration", "overrides": null, @@ -87,6 +88,7 @@ { "constant": false, "id": 10, + "mutability": "mutable", "name": "b", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/long_type_name_identifier_legacy.json b/test/libsolidity/ASTJSON/long_type_name_identifier_legacy.json index caf807c24..bc90e0d6a 100644 --- a/test/libsolidity/ASTJSON/long_type_name_identifier_legacy.json +++ b/test/libsolidity/ASTJSON/long_type_name_identifier_legacy.json @@ -40,6 +40,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "a", "overrides": null, "scope": 15, @@ -143,6 +144,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "b", "overrides": null, "scope": 13, diff --git a/test/libsolidity/ASTJSON/mappings.json b/test/libsolidity/ASTJSON/mappings.json index 0bd1ecd98..5c24e3a12 100644 --- a/test/libsolidity/ASTJSON/mappings.json +++ b/test/libsolidity/ASTJSON/mappings.json @@ -58,6 +58,7 @@ { "constant": false, "id": 8, + "mutability": "mutable", "name": "a", "nodeType": "VariableDeclaration", "overrides": null, @@ -113,6 +114,7 @@ { "constant": false, "id": 12, + "mutability": "mutable", "name": "b", "nodeType": "VariableDeclaration", "overrides": null, @@ -166,6 +168,7 @@ { "constant": false, "id": 16, + "mutability": "mutable", "name": "c", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/mappings_legacy.json b/test/libsolidity/ASTJSON/mappings_legacy.json index 79814effe..700097b66 100644 --- a/test/libsolidity/ASTJSON/mappings_legacy.json +++ b/test/libsolidity/ASTJSON/mappings_legacy.json @@ -80,6 +80,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "a", "overrides": null, "scope": 17, @@ -134,6 +135,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "b", "overrides": null, "scope": 17, @@ -186,6 +188,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "c", "overrides": null, "scope": 17, diff --git a/test/libsolidity/ASTJSON/modifier_definition.json b/test/libsolidity/ASTJSON/modifier_definition.json index 19f7ed184..a3c71159a 100644 --- a/test/libsolidity/ASTJSON/modifier_definition.json +++ b/test/libsolidity/ASTJSON/modifier_definition.json @@ -56,6 +56,7 @@ { "constant": false, "id": 2, + "mutability": "mutable", "name": "i", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/modifier_definition_legacy.json b/test/libsolidity/ASTJSON/modifier_definition_legacy.json index 8f028a474..369562171 100644 --- a/test/libsolidity/ASTJSON/modifier_definition_legacy.json +++ b/test/libsolidity/ASTJSON/modifier_definition_legacy.json @@ -54,6 +54,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "i", "overrides": null, "scope": 6, diff --git a/test/libsolidity/ASTJSON/modifier_invocation.json b/test/libsolidity/ASTJSON/modifier_invocation.json index 19f7ed184..a3c71159a 100644 --- a/test/libsolidity/ASTJSON/modifier_invocation.json +++ b/test/libsolidity/ASTJSON/modifier_invocation.json @@ -56,6 +56,7 @@ { "constant": false, "id": 2, + "mutability": "mutable", "name": "i", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/modifier_invocation_legacy.json b/test/libsolidity/ASTJSON/modifier_invocation_legacy.json index 8f028a474..369562171 100644 --- a/test/libsolidity/ASTJSON/modifier_invocation_legacy.json +++ b/test/libsolidity/ASTJSON/modifier_invocation_legacy.json @@ -54,6 +54,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "i", "overrides": null, "scope": 6, diff --git a/test/libsolidity/ASTJSON/mutability.json b/test/libsolidity/ASTJSON/mutability.json new file mode 100644 index 000000000..81d668702 --- /dev/null +++ b/test/libsolidity/ASTJSON/mutability.json @@ -0,0 +1,189 @@ +{ + "absolutePath": "a", + "exportedSymbols": + { + "C": + [ + 10 + ] + }, + "id": 11, + "nodeType": "SourceUnit", + "nodes": + [ + { + "abstract": false, + "baseContracts": [], + "contractDependencies": [], + "contractKind": "contract", + "documentation": null, + "fullyImplemented": true, + "id": 10, + "linearizedBaseContracts": + [ + 10 + ], + "name": "C", + "nodeType": "ContractDefinition", + "nodes": + [ + { + "constant": false, + "functionSelector": "0dbe671f", + "id": 3, + "mutability": "immutable", + "name": "a", + "nodeType": "VariableDeclaration", + "overrides": null, + "scope": 10, + "src": "17:27:1", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "typeName": + { + "id": 1, + "name": "uint", + "nodeType": "ElementaryTypeName", + "src": "17:4:1", + "typeDescriptions": + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "value": + { + "argumentTypes": null, + "hexValue": "34", + "id": 2, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "number", + "lValueRequested": false, + "nodeType": "Literal", + "src": "43:1:1", + "subdenomination": null, + "typeDescriptions": + { + "typeIdentifier": "t_rational_4_by_1", + "typeString": "int_const 4" + }, + "value": "4" + }, + "visibility": "public" + }, + { + "constant": true, + "functionSelector": "4df7e3d0", + "id": 6, + "mutability": "constant", + "name": "b", + "nodeType": "VariableDeclaration", + "overrides": null, + "scope": 10, + "src": "50:26:1", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "typeName": + { + "id": 4, + "name": "uint", + "nodeType": "ElementaryTypeName", + "src": "50:4:1", + "typeDescriptions": + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "value": + { + "argumentTypes": null, + "hexValue": "32", + "id": 5, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "number", + "lValueRequested": false, + "nodeType": "Literal", + "src": "75:1:1", + "subdenomination": null, + "typeDescriptions": + { + "typeIdentifier": "t_rational_2_by_1", + "typeString": "int_const 2" + }, + "value": "2" + }, + "visibility": "public" + }, + { + "constant": false, + "functionSelector": "c3da42b8", + "id": 9, + "mutability": "mutable", + "name": "c", + "nodeType": "VariableDeclaration", + "overrides": null, + "scope": 10, + "src": "82:17:1", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "typeName": + { + "id": 7, + "name": "uint", + "nodeType": "ElementaryTypeName", + "src": "82:4:1", + "typeDescriptions": + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "value": + { + "argumentTypes": null, + "hexValue": "33", + "id": 8, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "number", + "lValueRequested": false, + "nodeType": "Literal", + "src": "98:1:1", + "subdenomination": null, + "typeDescriptions": + { + "typeIdentifier": "t_rational_3_by_1", + "typeString": "int_const 3" + }, + "value": "3" + }, + "visibility": "public" + } + ], + "scope": 11, + "src": "0:102:1" + } + ], + "src": "0:103:1" +} diff --git a/test/libsolidity/ASTJSON/mutability.sol b/test/libsolidity/ASTJSON/mutability.sol new file mode 100644 index 000000000..7688186e7 --- /dev/null +++ b/test/libsolidity/ASTJSON/mutability.sol @@ -0,0 +1,8 @@ +contract C +{ + uint public immutable a = 4; + uint public constant b = 2; + uint public c = 3; +} + +// ---- diff --git a/test/libsolidity/ASTJSON/mutability_legacy.json b/test/libsolidity/ASTJSON/mutability_legacy.json new file mode 100644 index 000000000..98f28f636 --- /dev/null +++ b/test/libsolidity/ASTJSON/mutability_legacy.json @@ -0,0 +1,195 @@ +{ + "attributes": + { + "absolutePath": "a", + "exportedSymbols": + { + "C": + [ + 10 + ] + } + }, + "children": + [ + { + "attributes": + { + "abstract": false, + "baseContracts": + [ + null + ], + "contractDependencies": + [ + null + ], + "contractKind": "contract", + "documentation": null, + "fullyImplemented": true, + "linearizedBaseContracts": + [ + 10 + ], + "name": "C", + "scope": 11 + }, + "children": + [ + { + "attributes": + { + "constant": false, + "functionSelector": "0dbe671f", + "mutability": "immutable", + "name": "a", + "overrides": null, + "scope": 10, + "stateVariable": true, + "storageLocation": "default", + "type": "uint256", + "visibility": "public" + }, + "children": + [ + { + "attributes": + { + "name": "uint", + "type": "uint256" + }, + "id": 1, + "name": "ElementaryTypeName", + "src": "17:4:1" + }, + { + "attributes": + { + "argumentTypes": null, + "hexvalue": "34", + "isConstant": false, + "isLValue": false, + "isPure": true, + "lValueRequested": false, + "subdenomination": null, + "token": "number", + "type": "int_const 4", + "value": "4" + }, + "id": 2, + "name": "Literal", + "src": "43:1:1" + } + ], + "id": 3, + "name": "VariableDeclaration", + "src": "17:27:1" + }, + { + "attributes": + { + "constant": true, + "functionSelector": "4df7e3d0", + "mutability": "constant", + "name": "b", + "overrides": null, + "scope": 10, + "stateVariable": true, + "storageLocation": "default", + "type": "uint256", + "visibility": "public" + }, + "children": + [ + { + "attributes": + { + "name": "uint", + "type": "uint256" + }, + "id": 4, + "name": "ElementaryTypeName", + "src": "50:4:1" + }, + { + "attributes": + { + "argumentTypes": null, + "hexvalue": "32", + "isConstant": false, + "isLValue": false, + "isPure": true, + "lValueRequested": false, + "subdenomination": null, + "token": "number", + "type": "int_const 2", + "value": "2" + }, + "id": 5, + "name": "Literal", + "src": "75:1:1" + } + ], + "id": 6, + "name": "VariableDeclaration", + "src": "50:26:1" + }, + { + "attributes": + { + "constant": false, + "functionSelector": "c3da42b8", + "mutability": "mutable", + "name": "c", + "overrides": null, + "scope": 10, + "stateVariable": true, + "storageLocation": "default", + "type": "uint256", + "visibility": "public" + }, + "children": + [ + { + "attributes": + { + "name": "uint", + "type": "uint256" + }, + "id": 7, + "name": "ElementaryTypeName", + "src": "82:4:1" + }, + { + "attributes": + { + "argumentTypes": null, + "hexvalue": "33", + "isConstant": false, + "isLValue": false, + "isPure": true, + "lValueRequested": false, + "subdenomination": null, + "token": "number", + "type": "int_const 3", + "value": "3" + }, + "id": 8, + "name": "Literal", + "src": "98:1:1" + } + ], + "id": 9, + "name": "VariableDeclaration", + "src": "82:17:1" + } + ], + "id": 10, + "name": "ContractDefinition", + "src": "0:102:1" + } + ], + "id": 11, + "name": "SourceUnit", + "src": "0:103:1" +} diff --git a/test/libsolidity/ASTJSON/non_utf8.json b/test/libsolidity/ASTJSON/non_utf8.json index 18f6b12dc..c925389d7 100644 --- a/test/libsolidity/ASTJSON/non_utf8.json +++ b/test/libsolidity/ASTJSON/non_utf8.json @@ -45,6 +45,7 @@ { "constant": false, "id": 3, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/non_utf8_legacy.json b/test/libsolidity/ASTJSON/non_utf8_legacy.json index 9f7933020..d3a212b0c 100644 --- a/test/libsolidity/ASTJSON/non_utf8_legacy.json +++ b/test/libsolidity/ASTJSON/non_utf8_legacy.json @@ -100,6 +100,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 6, diff --git a/test/libsolidity/ASTJSON/short_type_name.json b/test/libsolidity/ASTJSON/short_type_name.json index 887f29a1d..75defa9ab 100644 --- a/test/libsolidity/ASTJSON/short_type_name.json +++ b/test/libsolidity/ASTJSON/short_type_name.json @@ -45,6 +45,7 @@ { "constant": false, "id": 7, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/short_type_name_legacy.json b/test/libsolidity/ASTJSON/short_type_name_legacy.json index 4d1de106b..0d428bcb1 100644 --- a/test/libsolidity/ASTJSON/short_type_name_legacy.json +++ b/test/libsolidity/ASTJSON/short_type_name_legacy.json @@ -101,6 +101,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 9, diff --git a/test/libsolidity/ASTJSON/short_type_name_ref.json b/test/libsolidity/ASTJSON/short_type_name_ref.json index 501184c9c..46096a914 100644 --- a/test/libsolidity/ASTJSON/short_type_name_ref.json +++ b/test/libsolidity/ASTJSON/short_type_name_ref.json @@ -45,6 +45,7 @@ { "constant": false, "id": 8, + "mutability": "mutable", "name": "rows", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/short_type_name_ref_legacy.json b/test/libsolidity/ASTJSON/short_type_name_ref_legacy.json index 4eec368b6..b1f4b88d2 100644 --- a/test/libsolidity/ASTJSON/short_type_name_ref_legacy.json +++ b/test/libsolidity/ASTJSON/short_type_name_ref_legacy.json @@ -101,6 +101,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "rows", "overrides": null, "scope": 10, diff --git a/test/libsolidity/ASTJSON/source_location.json b/test/libsolidity/ASTJSON/source_location.json index cc6dd33c9..54bffe378 100644 --- a/test/libsolidity/ASTJSON/source_location.json +++ b/test/libsolidity/ASTJSON/source_location.json @@ -45,6 +45,7 @@ { "constant": false, "id": 3, + "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, diff --git a/test/libsolidity/ASTJSON/source_location_legacy.json b/test/libsolidity/ASTJSON/source_location_legacy.json index dfde18975..dbd578dd2 100644 --- a/test/libsolidity/ASTJSON/source_location_legacy.json +++ b/test/libsolidity/ASTJSON/source_location_legacy.json @@ -100,6 +100,7 @@ "attributes": { "constant": false, + "mutability": "mutable", "name": "x", "overrides": null, "scope": 9, diff --git a/test/libsolidity/syntaxTests/immutable/double_specifier.sol b/test/libsolidity/syntaxTests/immutable/double_specifier.sol index 39f0f1e76..fec0f823b 100644 --- a/test/libsolidity/syntaxTests/immutable/double_specifier.sol +++ b/test/libsolidity/syntaxTests/immutable/double_specifier.sol @@ -3,5 +3,5 @@ contract C { uint immutable constant x; } // ---- -// ParserError: (32-41): Constantness already set to "immutable" -// ParserError: (64-72): Constantness already set to "immutable" +// ParserError: (32-41): Mutability already set to "immutable" +// ParserError: (64-72): Mutability already set to "immutable"