diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index cad676933..6fda89690 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -93,7 +93,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) if (contract.isLibrary()) { if (loc == Location::Memory) - fatalTypeError( + fatalTypeError(_variable.location(), "Location has to be calldata or storage for external " "library functions (remove the \"memory\" keyword)." ); @@ -102,7 +102,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) { // force location of external function parameters (not return) to calldata if (loc != Location::Default) - fatalTypeError( + fatalTypeError(_variable.location(), "Location has to be calldata for external functions " "(remove the \"memory\" or \"storage\" keyword)." ); @@ -115,7 +115,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) auto const& contract = dynamic_cast(*_variable.scope()->scope()); // force locations of public or external function (return) parameters to memory if (loc == Location::Storage && !contract.isLibrary()) - fatalTypeError( + fatalTypeError(_variable.location(), "Location has to be memory for publicly visible functions " "(remove the \"storage\" keyword)." ); @@ -127,7 +127,10 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) if (_variable.isConstant()) { if (loc != Location::Default && loc != Location::Memory) - fatalTypeError("Storage location has to be \"memory\" (or unspecified) for constants."); + fatalTypeError( + _variable.location(), + "Storage location has to be \"memory\" (or unspecified) for constants." + ); loc = Location::Memory; } if (loc == Location::Default) @@ -142,14 +145,14 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) } } else if (loc != Location::Default && !ref) - fatalTypeError("Storage location can only be given for array or struct types."); + fatalTypeError(_variable.location(), "Storage location can only be given for array or struct types."); if (!type) - fatalTypeError("Invalid type name."); + fatalTypeError(_variable.location(), "Invalid type name."); } else if (!_variable.canHaveAutoType()) - fatalTypeError("Explicit type needed."); + fatalTypeError(_variable.location(), "Explicit type needed."); // otherwise we have a "var"-declaration whose type is resolved by the first assignment _variable.annotation().type = type; @@ -175,7 +178,7 @@ TypePointer ReferencesResolver::typeFor(TypeName const& _typeName) else if (ContractDefinition const* contract = dynamic_cast(declaration)) type = make_shared(*contract); else - fatalTypeError("Name has to refer to a struct, enum or contract."); + fatalTypeError(typeName->location(), "Name has to refer to a struct, enum or contract."); } else if (auto mapping = dynamic_cast(&_typeName)) { @@ -191,7 +194,7 @@ TypePointer ReferencesResolver::typeFor(TypeName const& _typeName) { TypePointer baseType = typeFor(arrayType->baseType()); if (baseType->storageBytes() == 0) - fatalTypeError("Illegal base type of storage size zero for array."); + fatalTypeError(arrayType->location(), "Illegal base type of storage size zero for array."); if (Expression const* length = arrayType->length()) { if (!length->annotation().type) @@ -199,7 +202,7 @@ TypePointer ReferencesResolver::typeFor(TypeName const& _typeName) auto const* lengthType = dynamic_cast(length->annotation().type.get()); if (!lengthType) - fatalTypeError("Invalid array length."); + fatalTypeError(length->location(), "Invalid array length."); type = make_shared(DataLocation::Storage, baseType, lengthType->literalValue(nullptr)); } else @@ -209,7 +212,7 @@ TypePointer ReferencesResolver::typeFor(TypeName const& _typeName) return _typeName.annotation().type = move(type); } -void ReferencesResolver::typeError(string const& _description, SourceLocation const& _location) +void ReferencesResolver::typeError(SourceLocation const& _location, string const& _description) { auto err = make_shared(Error::Type::TypeError); *err << errinfo_sourceLocation(_location) << errinfo_comment(_description); @@ -217,9 +220,9 @@ void ReferencesResolver::typeError(string const& _description, SourceLocation co m_errors.push_back(err); } -void ReferencesResolver::fatalTypeError(string const& _description) +void ReferencesResolver::fatalTypeError(SourceLocation const& _location, string const& _description) { - typeError(_description); + typeError(_location, _description); BOOST_THROW_EXCEPTION(FatalError()); } diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index 8d03dae16..54b34a366 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -73,10 +73,10 @@ private: TypePointer typeFor(TypeName const& _typeName); /// Adds a new error to the list of errors. - void typeError(std::string const& _description, SourceLocation const& _location); + void typeError(SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors and throws to abort type checking. - void fatalTypeError(std::string const& _description); + void fatalTypeError(SourceLocation const& _location, std::string const& _description); ErrorList& m_errors; NameAndTypeResolver& m_resolver;