compiler: improve "function redeclared" error

This error can normally only happen with //go:linkname and such, but
it's nice to get an informative error message in that case.
This commit is contained in:
Ayke van Laethem
2019-12-31 18:47:00 +01:00
committed by Ron Evans
parent 69c1d802e1
commit 0933577e60
4 changed files with 34 additions and 16 deletions
+6 -1
View File
@@ -810,7 +810,12 @@ func (c *Compiler) parseFunc(frame *Frame) {
fmt.Printf("\nfunc %s:\n", frame.fn.Function)
}
if !frame.fn.LLVMFn.IsDeclaration() {
c.addError(frame.fn.Pos(), "function is already defined:"+frame.fn.LLVMFn.Name())
errValue := frame.fn.LLVMFn.Name() + " redeclared in this program"
fnPos := getPosition(frame.fn.LLVMFn)
if fnPos.IsValid() {
errValue += "\n\tprevious declaration at " + fnPos.String()
}
c.addError(frame.fn.Pos(), errValue)
return
}
if !frame.fn.IsExported() {