From af0af77d42381f7a82b5327c7efee7f2bfbae710 Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Sat, 6 Apr 2024 17:17:51 -0300 Subject: [PATCH] Make parser accept transient as location (but not a keyword) --- docs/grammar/SolidityLexer.g4 | 1 + docs/grammar/SolidityParser.g4 | 16 +++-- .../analysis/DeclarationTypeChecker.cpp | 27 +++++++- libsolidity/ast/AST.cpp | 4 +- libsolidity/ast/AST.h | 2 +- libsolidity/ast/ASTJsonExporter.cpp | 2 + libsolidity/ast/ASTJsonImporter.cpp | 2 + libsolidity/ast/Types.cpp | 17 +++++ libsolidity/ast/Types.h | 2 +- libsolidity/codegen/ArrayUtils.cpp | 6 ++ libsolidity/codegen/CompilerUtils.cpp | 9 +++ libsolidity/codegen/ExpressionCompiler.cpp | 6 ++ libsolidity/codegen/YulUtilFunctions.cpp | 3 + .../codegen/ir/IRGeneratorForStatements.cpp | 3 + libsolidity/parsing/Parser.cpp | 15 ++++ .../input.json | 16 +++++ .../output.json | 69 +++++++++++++++++++ .../transient_data_location.sol | 8 +++ ...onstant_state_variable_named_transient.sol | 4 ++ .../constant_transient_state_variable.sol | 5 ++ .../syntaxTests/contract_named_transient.sol | 1 + .../data_location_in_function_type_fail.sol | 3 + ...cifier_test_external_transient_storage.sol | 5 ++ ...tion_specifier_test_internal_transient.sol | 5 ++ ..._function_with_data_location_transient.sol | 15 ++++ ...tion_specifier_test_external_transient.sol | 5 ++ ...tion_specifier_test_internal_transient.sol | 5 ++ ...sient_data_location_function_parameter.sol | 6 ++ ...function_parameters_location_transient.sol | 5 ++ ...n_return_parameters_location_transient.sol | 5 ++ ...cation_specifier_test_public_transient.sol | 5 ++ ...n_return_parameters_location_transient.sol | 5 ++ .../state_variable_storage_transient.sol | 5 ++ .../state_variable_transient_storage.sol | 5 ++ .../dataLocations/transient_function_type.sol | 4 ++ .../transient_function_type_parameter.sol | 6 ++ .../transient_local_variable.sol | 7 ++ ...ansient_reference_type_state_variables.sol | 12 ++++ .../transient_state_variable_visibility.sol | 10 +++ .../transient_value_type_state_variables.sol | 10 +++ ..._value_type_state_variables_assignment.sol | 8 +++ ...tion_specifier_test_non_reference_type.sol | 3 + ...location_transient_test_reference_type.sol | 14 ++++ .../errors/invalid_parameter_location.sol | 5 ++ .../events/invalid_parameter_location.sol | 5 ++ .../events/transient_indexed_parameter.sol | 5 ++ .../function_type_with_transient_param.sol | 9 +++ ...nction_type_with_param_named_transient.sol | 5 ++ ...ent_function_type_with_transient_param.sol | 6 ++ .../immutable_state_var_named_transient.sol | 4 ++ .../state_var_transient_data_location.sol | 5 ++ .../modifiers/multiple_parameter_location.sol | 12 ++++ .../modifiers/transient_parameter.sol | 5 ++ .../operators/transient_value_type.sol | 9 +++ .../transient_data_location_member.sol | 5 ++ ...ate_variable_address_payable_transient.sol | 4 ++ ...ate_variable_address_transient_payable.sol | 5 ++ .../transient_as_identifier.sol | 25 +++++++ ...nsient_as_identifier_and_data_location.sol | 4 ++ 59 files changed, 470 insertions(+), 9 deletions(-) create mode 100644 test/cmdlineTests/storage_layout_transient_value_types/input.json create mode 100644 test/cmdlineTests/storage_layout_transient_value_types/output.json create mode 100644 test/libsolidity/astPropertyTests/transient_data_location.sol create mode 100644 test/libsolidity/syntaxTests/constants/constant_state_variable_named_transient.sol create mode 100644 test/libsolidity/syntaxTests/constants/constant_transient_state_variable.sol create mode 100644 test/libsolidity/syntaxTests/contract_named_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_transient_storage.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraries/library_function_with_data_location_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/multiple_transient_data_location_function_parameter.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_location_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_location_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_location_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/state_variable_storage_transient.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/state_variable_transient_storage.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_function_type.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_function_type_parameter.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_local_variable.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_reference_type_state_variables.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_state_variable_visibility.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables_assignment.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_transient_test_reference_type.sol create mode 100644 test/libsolidity/syntaxTests/events/transient_indexed_parameter.sol create mode 100644 test/libsolidity/syntaxTests/functionTypes/function_type_with_transient_param.sol create mode 100644 test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_param_named_transient.sol create mode 100644 test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_transient_param.sol create mode 100644 test/libsolidity/syntaxTests/immutable/immutable_state_var_named_transient.sol create mode 100644 test/libsolidity/syntaxTests/immutable/state_var_transient_data_location.sol create mode 100644 test/libsolidity/syntaxTests/modifiers/transient_parameter.sol create mode 100644 test/libsolidity/syntaxTests/operators/transient_value_type.sol create mode 100644 test/libsolidity/syntaxTests/structs/transient_data_location_member.sol create mode 100644 test/libsolidity/syntaxTests/types/address/state_variable_address_payable_transient.sol create mode 100644 test/libsolidity/syntaxTests/types/address/state_variable_address_transient_payable.sol create mode 100644 test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier.sol create mode 100644 test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier_and_data_location.sol diff --git a/docs/grammar/SolidityLexer.g4 b/docs/grammar/SolidityLexer.g4 index 43648ceb5d97..f994c331d536 100644 --- a/docs/grammar/SolidityLexer.g4 +++ b/docs/grammar/SolidityLexer.g4 @@ -85,6 +85,7 @@ SignedIntegerType: Storage: 'storage'; String: 'string'; Struct: 'struct'; +Transient: 'transient'; // not a real keyword True: 'true'; Try: 'try'; Type: 'type'; diff --git a/docs/grammar/SolidityParser.g4 b/docs/grammar/SolidityParser.g4 index e6d3ed7ccaea..27f2b2be2f0e 100644 --- a/docs/grammar/SolidityParser.g4 +++ b/docs/grammar/SolidityParser.g4 @@ -262,7 +262,7 @@ userDefinedValueTypeDefinition: * The declaration of a state variable. */ stateVariableDeclaration -locals [boolean constantnessSet = false, boolean visibilitySet = false, boolean overrideSpecifierSet = false] +locals [boolean constantnessSet = false, boolean visibilitySet = false, boolean overrideSpecifierSet = false, boolean transientLocationSet = false] : type=typeName ( @@ -272,8 +272,9 @@ locals [boolean constantnessSet = false, boolean visibilitySet = false, boolean | {!$constantnessSet}? Constant {$constantnessSet = true;} | {!$overrideSpecifierSet}? overrideSpecifier {$overrideSpecifierSet = true;} | {!$constantnessSet}? Immutable {$constantnessSet = true;} + | {!$transientLocationSet}? Transient {$transientLocationSet = true;} )* - name=identifier + (transientName=Transient | name=identifier) (Assign initialValue=expression)? Semicolon; @@ -364,7 +365,14 @@ locals [boolean visibilitySet = false, boolean mutabilitySet = false] /** * The declaration of a single variable. */ -variableDeclaration: type=typeName location=dataLocation? name=identifier; +variableDeclaration +: + type=typeName + ( + transientLocation=Transient name=identifier? + | location=dataLocation? name=identifier + ); + dataLocation: Memory | Storage | Calldata; /** @@ -419,7 +427,7 @@ inlineArrayExpression: LBrack (expression ( Comma expression)* ) RBrack; /** * Besides regular non-keyword Identifiers, some keywords like 'from' and 'error' can also be used as identifiers. */ -identifier: Identifier | From | Error | Revert | Global; +identifier: Identifier | From | Error | Revert | Global | Transient; literal: stringLiteral | numberLiteral | booleanLiteral | hexStringLiteral | unicodeStringLiteral; diff --git a/libsolidity/analysis/DeclarationTypeChecker.cpp b/libsolidity/analysis/DeclarationTypeChecker.cpp index 28c051c0a000..f191f09d93cd 100644 --- a/libsolidity/analysis/DeclarationTypeChecker.cpp +++ b/libsolidity/analysis/DeclarationTypeChecker.cpp @@ -407,6 +407,7 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) { case Location::Memory: return "\"memory\""; case Location::Storage: return "\"storage\""; + case Location::Transient: return "\"transient\""; case Location::CallData: return "\"calldata\""; case Location::Unspecified: return "none"; } @@ -456,8 +457,24 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) } else if (_variable.isStateVariable()) { - solAssert(varLoc == Location::Unspecified, ""); - typeLoc = (_variable.isConstant() || _variable.immutable()) ? DataLocation::Memory : DataLocation::Storage; + switch (varLoc) + { + case Location::Unspecified: + typeLoc = (_variable.isConstant() || _variable.immutable()) ? DataLocation::Memory : DataLocation::Storage; + break; + case Location::Transient: + if (_variable.isConstant() || _variable.immutable()) + m_errorReporter.declarationError( + 2197_error, + _variable.location(), + "Transient cannot be used as data location for constant or immutable variables." + ); + typeLoc = DataLocation::Transient; + break; + default: + solAssert(false, ""); + break; + } } else if ( dynamic_cast(_variable.scope()) || @@ -477,6 +494,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) case Location::CallData: typeLoc = DataLocation::CallData; break; + case Location::Transient: + solUnimplementedAssert(false, "Transient data location cannot be used in this kind of variable or parameter declaration."); + break; case Location::Unspecified: solAssert(!_variable.hasReferenceOrMappingType(), "Data location not properly set."); } @@ -497,6 +517,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) m_errorReporter.fatalTypeError(9259_error, _variable.location(), "Only constants of value type and byte array type are implemented."); } + if (!type->isValueType()) + solUnimplementedAssert(typeLoc != DataLocation::Transient, "Transient data location is only supported for value types."); + _variable.annotation().type = type; } diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index bae16967595b..a3aab07fba29 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -816,7 +816,9 @@ std::set VariableDeclaration::allowedDataLocation { using Location = VariableDeclaration::Location; - if (!hasReferenceOrMappingType() || isStateVariable() || isEventOrErrorParameter()) + if (isStateVariable()) + return std::set{Location::Unspecified, Location::Transient}; + else if (!hasReferenceOrMappingType() || isEventOrErrorParameter()) return std::set{ Location::Unspecified }; else if (isCallableOrCatchParameter()) { diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index d8b178377bd8..3494ab94b9b4 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -1052,7 +1052,7 @@ class FunctionDefinition: public CallableDeclaration, public StructurallyDocumen class VariableDeclaration: public Declaration, public StructurallyDocumented { public: - enum Location { Unspecified, Storage, Memory, CallData }; + enum Location { Unspecified, Storage, Transient, Memory, CallData }; enum class Mutability { Mutable, Immutable, Constant }; static std::string mutabilityToString(Mutability _mutability) { diff --git a/libsolidity/ast/ASTJsonExporter.cpp b/libsolidity/ast/ASTJsonExporter.cpp index f94b91674bcb..69f51618e3d4 100644 --- a/libsolidity/ast/ASTJsonExporter.cpp +++ b/libsolidity/ast/ASTJsonExporter.cpp @@ -1058,6 +1058,8 @@ std::string ASTJsonExporter::location(VariableDeclaration::Location _location) return "memory"; case VariableDeclaration::Location::CallData: return "calldata"; + case VariableDeclaration::Location::Transient: + return "transient"; } // To make the compiler happy return {}; diff --git a/libsolidity/ast/ASTJsonImporter.cpp b/libsolidity/ast/ASTJsonImporter.cpp index 5c1d4bdc0c30..728d77c0de8b 100644 --- a/libsolidity/ast/ASTJsonImporter.cpp +++ b/libsolidity/ast/ASTJsonImporter.cpp @@ -1190,6 +1190,8 @@ VariableDeclaration::Location ASTJsonImporter::location(Json const& _node) return VariableDeclaration::Location::Memory; else if (storageLocStr == "calldata") return VariableDeclaration::Location::CallData; + else if (storageLocStr == "transient") + return VariableDeclaration::Location::Transient; else astAssert(false, "Unknown location declaration"); diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 028b7667326f..4309a6f63887 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1544,6 +1544,8 @@ TypeResult ReferenceType::unaryOperatorResult(Token _operator) const return TypeProvider::emptyTuple(); case DataLocation::Storage: return isPointer() ? nullptr : TypeProvider::emptyTuple(); + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); } return nullptr; } @@ -1571,6 +1573,9 @@ std::string ReferenceType::stringForReferencePart() const return "calldata"; case DataLocation::Memory: return "memory"; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; } solAssert(false, ""); return ""; @@ -1584,6 +1589,9 @@ std::string ReferenceType::identifierLocationSuffix() const case DataLocation::Storage: id += "_storage"; break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::Memory: id += "_memory"; break; @@ -1748,6 +1756,9 @@ BoolResult ArrayType::validForLocation(DataLocation _loc) const if (storageSizeUpperBound() >= bigint(1) << 256) return BoolResult::err("Type too large for storage."); break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; } return true; } @@ -1828,6 +1839,9 @@ std::vector> ArrayType::makeStackItems() co case DataLocation::Storage: // byte offset inside storage value is omitted return {std::make_tuple("slot", TypeProvider::uint256())}; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; } solAssert(false, ""); } @@ -2568,6 +2582,9 @@ std::vector> StructType::makeStackItems() c return {std::make_tuple("mpos", TypeProvider::uint256())}; case DataLocation::Storage: return {std::make_tuple("slot", TypeProvider::uint256())}; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; } solAssert(false, ""); } diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 3ab4a1d97ebc..1817c97af4dd 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -70,7 +70,7 @@ inline rational makeRational(bigint const& _numerator, bigint const& _denominato return rational(_numerator, _denominator); } -enum class DataLocation { Storage, CallData, Memory }; +enum class DataLocation { Storage, Transient, CallData, Memory }; /** diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index e73ddfbae819..7990c08bd177 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -1021,6 +1021,9 @@ void ArrayUtils::retrieveLength(ArrayType const& _arrayType, unsigned _stackDept if (_arrayType.isByteArrayOrString()) m_context.callYulFunction(m_context.utilFunctions().extractByteArrayLengthFunction(), 1, 1); break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; } } } @@ -1118,6 +1121,9 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType, bool _doBoundsCheck, b m_context << endTag; break; } + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; } } diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index bf4f25bf289e..1776bfe0b504 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1024,6 +1024,9 @@ void CompilerUtils::convertType( "Invalid conversion to storage type." ); break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::Memory: { // Copy the array to a free position in memory, unless it is already in memory. @@ -1168,6 +1171,9 @@ void CompilerUtils::convertType( "Invalid conversion to storage type." ); break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::Memory: // Copy the array to a free position in memory, unless it is already in memory. switch (typeOnStack.location()) @@ -1207,6 +1213,9 @@ void CompilerUtils::convertType( conversionImpl(m_context); break; } + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::CallData: { if (typeOnStack.isDynamicallyEncoded()) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 54090f960437..2152c8aad255 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -2047,6 +2047,9 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) ArrayUtils(m_context).retrieveLength(type); m_context << Instruction::SWAP1 << Instruction::POP; break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::Memory: m_context << Instruction::MLOAD; break; @@ -2193,6 +2196,9 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess) else setLValueToStorageItem(_indexAccess); break; + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::Memory: ArrayUtils(m_context).accessIndex(arrayType); setLValue(_indexAccess, *_indexAccess.annotation().type, !arrayType.isByteArrayOrString()); diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index b71dfd566a75..bfc1a60b08e8 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -2525,6 +2525,9 @@ std::string YulUtilFunctions::nextArrayElementFunction(ArrayType const& _type) templ("advance", toCompactHexWithPrefix(size)); break; } + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::CallData: { u256 size = _type.calldataStride(); diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 2464fefc434b..44799979f976 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -2314,6 +2314,9 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess) break; } + case DataLocation::Transient: + solUnimplementedAssert(false, "Transient data location is only supported for value types."); + break; case DataLocation::Memory: { std::string const indexAccessFunction = m_utils.memoryArrayIndexAccessFunction(arrayType); diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index f650e0dbf1dc..6c209046741f 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -886,6 +886,21 @@ ASTPointer Parser::parseVariableDeclaration( } } } + else if ( + (_options.kind == VarDeclKind::State || _options.allowLocationSpecifier) && + token == Token::Identifier && + m_scanner->currentLiteral() == "transient" && + m_scanner->peekNextToken() != Token::Assign && + m_scanner->peekNextToken() != Token::Semicolon && + m_scanner->peekNextToken() != Token::Comma && + m_scanner->peekNextToken() != Token::RParen + ) + { + if (location != VariableDeclaration::Location::Unspecified) + parserError(ErrorId{3548}, "Location already specified."); + else + location = VariableDeclaration::Location::Transient; + } else break; nodeFactory.markEndPosition(); diff --git a/test/cmdlineTests/storage_layout_transient_value_types/input.json b/test/cmdlineTests/storage_layout_transient_value_types/input.json new file mode 100644 index 000000000000..bf7fc2cb9840 --- /dev/null +++ b/test/cmdlineTests/storage_layout_transient_value_types/input.json @@ -0,0 +1,16 @@ +{ + "language": "Solidity", + "sources": { + "fileA": { + "content": "//SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;\ncontract A { uint transient x; bytes32 transient b; address transient addr; }" + } + }, + "settings": { + "outputSelection": { + "fileA": { + "A": [ "storageLayout" ], + "": [ "storageLayout" ] + } + } + } +} diff --git a/test/cmdlineTests/storage_layout_transient_value_types/output.json b/test/cmdlineTests/storage_layout_transient_value_types/output.json new file mode 100644 index 000000000000..b6eb007805a4 --- /dev/null +++ b/test/cmdlineTests/storage_layout_transient_value_types/output.json @@ -0,0 +1,69 @@ +{ + "contracts": + { + "fileA": + { + "A": + { + "storageLayout": + { + "storage": + [ + { + "astId": 3, + "contract": "fileA:A", + "label": "x", + "offset": 0, + "slot": "0", + "type": "t_uint256" + }, + { + "astId": 5, + "contract": "fileA:A", + "label": "b", + "offset": 0, + "slot": "1", + "type": "t_bytes32" + }, + { + "astId": 7, + "contract": "fileA:A", + "label": "addr", + "offset": 0, + "slot": "2", + "type": "t_address" + } + ], + "types": + { + "t_address": + { + "encoding": "inplace", + "label": "address", + "numberOfBytes": "20" + }, + "t_bytes32": + { + "encoding": "inplace", + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_uint256": + { + "encoding": "inplace", + "label": "uint256", + "numberOfBytes": "32" + } + } + } + } + } + }, + "sources": + { + "fileA": + { + "id": 0 + } + } +} diff --git a/test/libsolidity/astPropertyTests/transient_data_location.sol b/test/libsolidity/astPropertyTests/transient_data_location.sol new file mode 100644 index 000000000000..6a937414d6bd --- /dev/null +++ b/test/libsolidity/astPropertyTests/transient_data_location.sol @@ -0,0 +1,8 @@ +contract C { + /// TestVarDataLocation: storageLocation + /// TestVarName: name + uint transient transient; +} +// ---- +// TestVarDataLocation: transient +// TestVarName: transient diff --git a/test/libsolidity/syntaxTests/constants/constant_state_variable_named_transient.sol b/test/libsolidity/syntaxTests/constants/constant_state_variable_named_transient.sol new file mode 100644 index 000000000000..4d9873d36d07 --- /dev/null +++ b/test/libsolidity/syntaxTests/constants/constant_state_variable_named_transient.sol @@ -0,0 +1,4 @@ +contract C { + int constant public transient = 0; +} +// ---- diff --git a/test/libsolidity/syntaxTests/constants/constant_transient_state_variable.sol b/test/libsolidity/syntaxTests/constants/constant_transient_state_variable.sol new file mode 100644 index 000000000000..f9a722a1b4a8 --- /dev/null +++ b/test/libsolidity/syntaxTests/constants/constant_transient_state_variable.sol @@ -0,0 +1,5 @@ +contract C { + int constant public transient x = 0; +} +// ---- +// DeclarationError 2197: (17-52): Transient cannot be used as data location for constant or immutable variables. diff --git a/test/libsolidity/syntaxTests/contract_named_transient.sol b/test/libsolidity/syntaxTests/contract_named_transient.sol new file mode 100644 index 000000000000..853396f21bb5 --- /dev/null +++ b/test/libsolidity/syntaxTests/contract_named_transient.sol @@ -0,0 +1 @@ +contract transient {} diff --git a/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type_fail.sol b/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type_fail.sol index 4e5091e8c1cf..b057fe6603ee 100644 --- a/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type_fail.sol +++ b/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type_fail.sol @@ -2,7 +2,10 @@ library L { struct Nested { uint y; } function b(function(Nested calldata) external returns (uint)[] storage) external pure {} function d(function(Nested storage) external returns (uint)[] storage) external pure {} + function d(function(Nested transient x) external returns (uint)[] storage) external pure {} } // ---- +// Warning 6162: (251-269): Naming function type parameters is deprecated. // TypeError 6651: (159-173): Data location must be "memory" or "calldata" for parameter in function, but "storage" was given. +// TypeError 6651: (251-269): Data location must be "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_transient_storage.sol b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_transient_storage.sol new file mode 100644 index 000000000000..02f80e3d5b27 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_transient_storage.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes transient x) external; +} +// ---- +// TypeError 6651: (31-48): Data location must be "memory" or "calldata" for parameter in external function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_transient.sol b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_transient.sol new file mode 100644 index 000000000000..eec28bf40ca5 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_transient.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes transient x) internal {} +} +// ---- +// TypeError 6651: (31-48): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/libraries/library_function_with_data_location_transient.sol b/test/libsolidity/syntaxTests/dataLocations/libraries/library_function_with_data_location_transient.sol new file mode 100644 index 000000000000..2e117f3bc7a5 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraries/library_function_with_data_location_transient.sol @@ -0,0 +1,15 @@ +library L { + function f(uint[] transient a) private pure returns (uint[] transient x) { } + function g(uint[] transient b) internal pure returns (uint[] transient y) { } + function h(uint[] transient c) public pure returns (uint[] transient w) { } + function i(uint[] transient d) external pure returns (uint[] transient z) { } +} +// ---- +// TypeError 6651: (27-45): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. +// TypeError 6651: (69-87): Data location must be "storage", "memory" or "calldata" for return parameter in function, but "transient" was given. +// TypeError 6651: (108-126): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. +// TypeError 6651: (151-169): Data location must be "storage", "memory" or "calldata" for return parameter in function, but "transient" was given. +// TypeError 6651: (190-208): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. +// TypeError 6651: (231-249): Data location must be "storage", "memory" or "calldata" for return parameter in function, but "transient" was given. +// TypeError 6651: (270-288): Data location must be "storage", "memory" or "calldata" for parameter in external function, but "transient" was given. +// TypeError 6651: (313-331): Data location must be "storage", "memory" or "calldata" for return parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_transient.sol b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_transient.sol new file mode 100644 index 000000000000..9f701e324378 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryExternalFunction/function_argument_location_specifier_test_external_transient.sol @@ -0,0 +1,5 @@ +library test { + function f(bytes transient x) external {} +} +// ---- +// TypeError 6651: (30-47): Data location must be "storage", "memory" or "calldata" for parameter in external function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_transient.sol b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_transient.sol new file mode 100644 index 000000000000..5c11c18c105c --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraryInternalFunction/function_argument_location_specifier_test_internal_transient.sol @@ -0,0 +1,5 @@ +library test { + function f(bytes transient x) internal pure {} +} +// ---- +// TypeError 6651: (30-47): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/multiple_transient_data_location_function_parameter.sol b/test/libsolidity/syntaxTests/dataLocations/multiple_transient_data_location_function_parameter.sol new file mode 100644 index 000000000000..feafa9fc75d2 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/multiple_transient_data_location_function_parameter.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint[] transient transient x) public pure { } +} + +// ---- +// ParserError 3548: (45-54): Location already specified. diff --git a/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_location_transient.sol b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_location_transient.sol new file mode 100644 index 000000000000..c0d06ec60eac --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_location_transient.sol @@ -0,0 +1,5 @@ +contract C { + function f(uint[] transient x) private pure {} +} +// ---- +// TypeError 6651: (28-46): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_location_transient.sol b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_location_transient.sol new file mode 100644 index 000000000000..2695426d0d47 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_location_transient.sol @@ -0,0 +1,5 @@ +contract C { + function f() private pure returns (uint[] transient x) {} +} +// ---- +// TypeError 6651: (52-70): Data location must be "storage", "memory" or "calldata" for return parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_transient.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_transient.sol new file mode 100644 index 000000000000..bd0875e9a54d --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_transient.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes transient x) public; +} +// ---- +// TypeError 6651: (31-48): Data location must be "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_location_transient.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_location_transient.sol new file mode 100644 index 000000000000..5bf68fea6d79 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_location_transient.sol @@ -0,0 +1,5 @@ +contract C { + function h() public pure returns(uint[] transient x) {} +} +// ---- +// TypeError 6651: (50-68): Data location must be "memory" or "calldata" for return parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/state_variable_storage_transient.sol b/test/libsolidity/syntaxTests/dataLocations/state_variable_storage_transient.sol new file mode 100644 index 000000000000..d3fb023e0dbd --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/state_variable_storage_transient.sol @@ -0,0 +1,5 @@ +contract C { + uint storage transient x; +} +// ---- +// ParserError 2314: (22-29): Expected identifier but got 'storage' diff --git a/test/libsolidity/syntaxTests/dataLocations/state_variable_transient_storage.sol b/test/libsolidity/syntaxTests/dataLocations/state_variable_transient_storage.sol new file mode 100644 index 000000000000..53260194d1d2 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/state_variable_transient_storage.sol @@ -0,0 +1,5 @@ +contract C { + uint transient storage x; +} +// ---- +// ParserError 2314: (32-39): Expected identifier but got 'storage' diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_function_type.sol b/test/libsolidity/syntaxTests/dataLocations/transient_function_type.sol new file mode 100644 index 000000000000..711f8fb3ed37 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_function_type.sol @@ -0,0 +1,4 @@ +contract C { + function (uint) external transient y; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_function_type_parameter.sol b/test/libsolidity/syntaxTests/dataLocations/transient_function_type_parameter.sol new file mode 100644 index 000000000000..a35e1c3d6ff7 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_function_type_parameter.sol @@ -0,0 +1,6 @@ +contract C { + function (uint transient x) external y; +} +// ---- +// Warning 6162: (27-43): Naming function type parameters is deprecated. +// TypeError 6651: (27-43): Data location can only be specified for array, struct or mapping types, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_local_variable.sol b/test/libsolidity/syntaxTests/dataLocations/transient_local_variable.sol new file mode 100644 index 000000000000..e89b078bafbb --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_local_variable.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure { + uint transient x = 0; + } +} +// ---- +// TypeError 6651: (52-68): Data location can only be specified for array, struct or mapping types, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_reference_type_state_variables.sol b/test/libsolidity/syntaxTests/dataLocations/transient_reference_type_state_variables.sol new file mode 100644 index 000000000000..b7fa7e9a9715 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_reference_type_state_variables.sol @@ -0,0 +1,12 @@ +struct S { + uint x; + address a; +} + +contract C { + uint[] transient x; + S transient s; + mapping(uint => uint) transient y; +} +// ---- +// UnimplementedFeatureError: Transient data location is only supported for value types. diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_state_variable_visibility.sol b/test/libsolidity/syntaxTests/dataLocations/transient_state_variable_visibility.sol new file mode 100644 index 000000000000..31cc5357d309 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_state_variable_visibility.sol @@ -0,0 +1,10 @@ +contract C { + uint public transient pubt; + uint internal transient it; + uint private transient prvt; + + uint transient public tpub; + uint transient internal ti; + uint transient private tprv; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables.sol b/test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables.sol new file mode 100644 index 000000000000..77667e4c88a6 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables.sol @@ -0,0 +1,10 @@ +contract D { } + +contract C { + address transient a; + bool transient b; + D transient d; + uint transient x; + bytes32 transient y; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables_assignment.sol b/test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables_assignment.sol new file mode 100644 index 000000000000..bf522af93506 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/transient_value_type_state_variables_assignment.sol @@ -0,0 +1,8 @@ +contract D { } + +contract C { + int transient x = -99; + address transient a = address(0xABC); + bool transient b = x > 0 ? false : true; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol index 8c7a2ecb96a6..c34ba88e528e 100644 --- a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol +++ b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol @@ -4,6 +4,8 @@ contract test { bytes16 storage b1; uint memory a2; bytes16 memory b2; + uint transient a3; + bytes16 b3; } } // ---- @@ -11,3 +13,4 @@ contract test { // TypeError 6651: (71-89): Data location can only be specified for array, struct or mapping types, but "storage" was given. // TypeError 6651: (97-111): Data location can only be specified for array, struct or mapping types, but "memory" was given. // TypeError 6651: (119-136): Data location can only be specified for array, struct or mapping types, but "memory" was given. +// TypeError 6651: (144-161): Data location can only be specified for array, struct or mapping types, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_transient_test_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_transient_test_reference_type.sol new file mode 100644 index 000000000000..39bdd5889fdc --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_transient_test_reference_type.sol @@ -0,0 +1,14 @@ +contract test { + struct S { + uint x; + } + S transient b; + + uint[] transient a; + function f() public { + uint[] transient c; + S transient d; + } +} +// ---- +// UnimplementedFeatureError: Transient data location is only supported for value types. diff --git a/test/libsolidity/syntaxTests/errors/invalid_parameter_location.sol b/test/libsolidity/syntaxTests/errors/invalid_parameter_location.sol index a116188d2375..38f1bd9af5b8 100644 --- a/test/libsolidity/syntaxTests/errors/invalid_parameter_location.sol +++ b/test/libsolidity/syntaxTests/errors/invalid_parameter_location.sol @@ -10,7 +10,12 @@ contract test { contract test { error e1(string calldata a); } +==== Source: D ==== +contract test { + error e1(string transient a); +} // ---- // ParserError 2314: (A:36-43): Expected ',' but got 'storage' // ParserError 2314: (B:36-42): Expected ',' but got 'memory' // ParserError 2314: (C:36-44): Expected ',' but got 'calldata' +// ParserError 2314: (D:46-47): Expected ',' but got identifier diff --git a/test/libsolidity/syntaxTests/events/invalid_parameter_location.sol b/test/libsolidity/syntaxTests/events/invalid_parameter_location.sol index 04ee9b7bc4b6..1f13bbf9085e 100644 --- a/test/libsolidity/syntaxTests/events/invalid_parameter_location.sol +++ b/test/libsolidity/syntaxTests/events/invalid_parameter_location.sol @@ -10,7 +10,12 @@ contract test { contract test { event e1(string calldata a); } +==== Source: D ==== +contract test { + event e1(string transient a); +} // ---- // ParserError 2314: (A:36-43): Expected ',' but got 'storage' // ParserError 2314: (B:36-42): Expected ',' but got 'memory' // ParserError 2314: (C:36-44): Expected ',' but got 'calldata' +// ParserError 2314: (D:46-47): Expected ',' but got identifier diff --git a/test/libsolidity/syntaxTests/events/transient_indexed_parameter.sol b/test/libsolidity/syntaxTests/events/transient_indexed_parameter.sol new file mode 100644 index 000000000000..718451de2fb6 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/transient_indexed_parameter.sol @@ -0,0 +1,5 @@ +contract C { + event e(string indexed transient a); +} +// ---- +// ParserError 2314: (50-51): Expected ',' but got identifier diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_with_transient_param.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_with_transient_param.sol new file mode 100644 index 000000000000..6c0cc737e6cf --- /dev/null +++ b/test/libsolidity/syntaxTests/functionTypes/function_type_with_transient_param.sol @@ -0,0 +1,9 @@ +contract C { + function (uint transient x) external y; + function (uint[] transient w) external z; +} +// ---- +// Warning 6162: (27-43): Naming function type parameters is deprecated. +// Warning 6162: (71-89): Naming function type parameters is deprecated. +// TypeError 6651: (27-43): Data location can only be specified for array, struct or mapping types, but "transient" was given. +// TypeError 6651: (71-89): Data location must be "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_param_named_transient.sol b/test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_param_named_transient.sol new file mode 100644 index 000000000000..40fbecbafaaf --- /dev/null +++ b/test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_param_named_transient.sol @@ -0,0 +1,5 @@ +contract C { + function (uint transient) external transient y; +} +// ---- +// Warning 6162: (27-41): Naming function type parameters is deprecated. diff --git a/test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_transient_param.sol b/test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_transient_param.sol new file mode 100644 index 000000000000..6c78a908a26c --- /dev/null +++ b/test/libsolidity/syntaxTests/functionTypes/transient_function_type_with_transient_param.sol @@ -0,0 +1,6 @@ +contract C { + function (uint transient x) external transient y; +} +// ---- +// Warning 6162: (27-43): Naming function type parameters is deprecated. +// TypeError 6651: (27-43): Data location can only be specified for array, struct or mapping types, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/immutable/immutable_state_var_named_transient.sol b/test/libsolidity/syntaxTests/immutable/immutable_state_var_named_transient.sol new file mode 100644 index 000000000000..c0ac3a8abb3c --- /dev/null +++ b/test/libsolidity/syntaxTests/immutable/immutable_state_var_named_transient.sol @@ -0,0 +1,4 @@ +contract C { + address public immutable transient; +} +// ---- diff --git a/test/libsolidity/syntaxTests/immutable/state_var_transient_data_location.sol b/test/libsolidity/syntaxTests/immutable/state_var_transient_data_location.sol new file mode 100644 index 000000000000..a3d93848d9a2 --- /dev/null +++ b/test/libsolidity/syntaxTests/immutable/state_var_transient_data_location.sol @@ -0,0 +1,5 @@ +contract C { + uint public immutable transient x; +} +// ---- +// DeclarationError 2197: (17-50): Transient cannot be used as data location for constant or immutable variables. diff --git a/test/libsolidity/syntaxTests/modifiers/multiple_parameter_location.sol b/test/libsolidity/syntaxTests/modifiers/multiple_parameter_location.sol index e264a593ff2c..03d0ff1201ec 100644 --- a/test/libsolidity/syntaxTests/modifiers/multiple_parameter_location.sol +++ b/test/libsolidity/syntaxTests/modifiers/multiple_parameter_location.sol @@ -8,6 +8,12 @@ contract A { modifier mod7(string calldata storage a) { _; } modifier mod8(string calldata memory a) { _; } modifier mod9(string calldata calldata a) { _; } + modifier modA(string transient storage a) { _; } + modifier modB(string transient memory a) { _; } + modifier modC(string transient calldata a) { _; } + modifier modD(string storage transient a) { _; } + modifier modE(string memory transient a) { _; } + modifier modF(string calldata transient a) { _; } } // ---- // ParserError 3548: (46-53): Location already specified. @@ -19,3 +25,9 @@ contract A { // ParserError 3548: (350-357): Location already specified. // ParserError 3548: (402-408): Location already specified. // ParserError 3548: (453-461): Location already specified. +// ParserError 3548: (507-514): Location already specified. +// ParserError 3548: (560-566): Location already specified. +// ParserError 3548: (612-620): Location already specified. +// ParserError 3548: (664-673): Location already specified. +// ParserError 3548: (716-725): Location already specified. +// ParserError 3548: (770-779): Location already specified. diff --git a/test/libsolidity/syntaxTests/modifiers/transient_parameter.sol b/test/libsolidity/syntaxTests/modifiers/transient_parameter.sol new file mode 100644 index 000000000000..19fb59eac561 --- /dev/null +++ b/test/libsolidity/syntaxTests/modifiers/transient_parameter.sol @@ -0,0 +1,5 @@ +contract A { + modifier mod2(uint[] transient b) { _; } +} +// ---- +// TypeError 6651: (31-49): Data location must be "storage", "memory" or "calldata" for parameter in function, but "transient" was given. diff --git a/test/libsolidity/syntaxTests/operators/transient_value_type.sol b/test/libsolidity/syntaxTests/operators/transient_value_type.sol new file mode 100644 index 000000000000..1e24abb11468 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/transient_value_type.sol @@ -0,0 +1,9 @@ +contract C { + int transient x; + function f() public view returns (int) { + int y = x; + int w = -x; + return (x + w) * (y / x); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/structs/transient_data_location_member.sol b/test/libsolidity/syntaxTests/structs/transient_data_location_member.sol new file mode 100644 index 000000000000..110d4969a6cc --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/transient_data_location_member.sol @@ -0,0 +1,5 @@ +struct S { + int transient x; +} +// ---- +// ParserError 2314: (29-30): Expected ';' but got identifier diff --git a/test/libsolidity/syntaxTests/types/address/state_variable_address_payable_transient.sol b/test/libsolidity/syntaxTests/types/address/state_variable_address_payable_transient.sol new file mode 100644 index 000000000000..9aec594b3709 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/state_variable_address_payable_transient.sol @@ -0,0 +1,4 @@ +contract C { + address payable transient a; +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/state_variable_address_transient_payable.sol b/test/libsolidity/syntaxTests/types/address/state_variable_address_transient_payable.sol new file mode 100644 index 000000000000..16d8adb493f8 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/state_variable_address_transient_payable.sol @@ -0,0 +1,5 @@ +contract C { + address transient payable a; +} +// ---- +// ParserError 2314: (35-42): Expected identifier but got 'payable' diff --git a/test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier.sol b/test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier.sol new file mode 100644 index 000000000000..ced189faf061 --- /dev/null +++ b/test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier.sol @@ -0,0 +1,25 @@ +contract C { + function transient() public pure { } +} + +error CustomError(uint transient); +event e1(uint transient); +event e2(uint indexed transient); + +struct S { + int transient; +} + +contract D { + function f() public pure returns (uint) { + uint transient = 1; + return transient; + } + + function g(int transient) public pure { } + + modifier m(address transient) { + _; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier_and_data_location.sol b/test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier_and_data_location.sol new file mode 100644 index 000000000000..862e16269ec0 --- /dev/null +++ b/test/libsolidity/syntaxTests/variableDeclaration/transient_as_identifier_and_data_location.sol @@ -0,0 +1,4 @@ +contract C { + uint transient transient; +} +// ----