Improve error message about incompatible function types.
When reporting that a function has illegally been overloaded only by return type, include "task", "export", and "extern "C"", as appropriate in the error message to make clear what the issue is. Finishes issue #216.
This commit is contained in:
@@ -506,10 +506,13 @@ Module::AddFunctionDeclaration(Symbol *funSym, bool isInline) {
|
||||
break;
|
||||
}
|
||||
if (i == functionType->GetNumParameters()) {
|
||||
std::string thisRetType = functionType->GetReturnTypeString();
|
||||
std::string otherRetType = ofType->GetReturnTypeString();
|
||||
Error(funSym->pos, "Illegal to overload function by return "
|
||||
"type only (previous declaration was at line %d of "
|
||||
"file %s).", overloadFunc->pos.first_line,
|
||||
overloadFunc->pos.name);
|
||||
"type only. This function returns \"%s\" while "
|
||||
"previous declaration at %s:%d returns \"%s\".",
|
||||
thisRetType.c_str(), overloadFunc->pos.name,
|
||||
overloadFunc->pos.first_line, otherRetType.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
13
type.cpp
13
type.cpp
@@ -2552,6 +2552,19 @@ FunctionType::GetDIType(llvm::DIDescriptor scope) const {
|
||||
}
|
||||
|
||||
|
||||
const std::string
|
||||
FunctionType::GetReturnTypeString() const {
|
||||
std::string ret;
|
||||
if (isTask)
|
||||
ret += "task ";
|
||||
if (isExported)
|
||||
ret += "export ";
|
||||
if (isExternC)
|
||||
ret += "extern \"C\" ";
|
||||
return ret + returnType->GetString();
|
||||
}
|
||||
|
||||
|
||||
LLVM_TYPE_CONST llvm::FunctionType *
|
||||
FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool includeMask) const {
|
||||
if (isTask == true)
|
||||
|
||||
2
type.h
2
type.h
@@ -776,6 +776,8 @@ public:
|
||||
|
||||
const Type *GetReturnType() const { return returnType; }
|
||||
|
||||
const std::string GetReturnTypeString() const;
|
||||
|
||||
/** This method returns the LLVM FunctionType that corresponds to this
|
||||
function type. The \c includeMask parameter indicates whether the
|
||||
llvm::FunctionType should have a mask as the last argument in its
|
||||
|
||||
Reference in New Issue
Block a user