aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler/errors.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-12-31 18:47:00 +0100
committerRon Evans <[email protected]>2020-01-04 10:24:14 +0100
commit0933577e6084c1f95709d0cbae265b8bfb701be6 (patch)
tree6889950255922e7d0c198e06dec7d361851e24ef /compiler/errors.go
parent69c1d802e13155c016657de9b29849eae00d3153 (diff)
downloadtinygo-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.go39
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()),
- }
}