diff options
author | Ayke van Laethem <[email protected]> | 2019-12-31 18:47:00 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-01-04 10:24:14 +0100 |
commit | 0933577e6084c1f95709d0cbae265b8bfb701be6 (patch) | |
tree | 6889950255922e7d0c198e06dec7d361851e24ef /compiler/errors.go | |
parent | 69c1d802e13155c016657de9b29849eae00d3153 (diff) | |
download | tinygo-0933577e6084c1f95709d0cbae265b8bfb701be6.tar.gz tinygo-0933577e6084c1f95709d0cbae265b8bfb701be6.zip |
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.
Diffstat (limited to 'compiler/errors.go')
-rw-r--r-- | compiler/errors.go | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/compiler/errors.go b/compiler/errors.go index f47ad991c..b2d8cc766 100644 --- a/compiler/errors.go +++ b/compiler/errors.go @@ -31,20 +31,31 @@ func errorAt(inst llvm.Value, msg string) scanner.Error { } } -// getPosition returns the position information for the given instruction, as -// far as it is available. -func getPosition(inst llvm.Value) token.Position { - if inst.IsAInstruction().IsNil() { +// getPosition returns the position information for the given value, as far as +// it is available. +func getPosition(val llvm.Value) token.Position { + if !val.IsAInstruction().IsNil() { + loc := val.InstructionDebugLoc() + if loc.IsNil() { + return token.Position{} + } + file := loc.LocationScope().ScopeFile() + return token.Position{ + Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), + Line: int(loc.LocationLine()), + Column: int(loc.LocationColumn()), + } + } else if !val.IsAFunction().IsNil() { + loc := val.Subprogram() + if loc.IsNil() { + return token.Position{} + } + file := loc.ScopeFile() + return token.Position{ + Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), + Line: int(loc.SubprogramLine()), + } + } else { return token.Position{} } - loc := inst.InstructionDebugLoc() - if loc.IsNil() { - return token.Position{} - } - file := loc.LocationScope().ScopeFile() - return token.Position{ - Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), - Line: int(loc.LocationLine()), - Column: int(loc.LocationColumn()), - } } |