diff options
author | Ayke van Laethem <[email protected]> | 2019-05-17 14:33:38 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-05-17 19:37:20 +0200 |
commit | 7ada00790c88f4d7f9dfd365a3a78e67da642c01 (patch) | |
tree | 6357df4ad5cd9a3a0a1e90796a2071b84f2a4248 /cgo/libclang.go | |
parent | dfa713040a7b3be012dc229996440005734aa9b4 (diff) | |
download | tinygo-7ada00790c88f4d7f9dfd365a3a78e67da642c01.tar.gz tinygo-7ada00790c88f4d7f9dfd365a3a78e67da642c01.zip |
cgo: print better error messages for unknown types
Types used in a program may not be implemented. Print a nice error
message explaining the situation, instead of just prepending C. to the
type spelling (and hoping the user knows what that undefined reference
means).
Diffstat (limited to 'cgo/libclang.go')
-rw-r--r-- | cgo/libclang.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cgo/libclang.go b/cgo/libclang.go index cca4487ec..ce6df7667 100644 --- a/cgo/libclang.go +++ b/cgo/libclang.go @@ -613,9 +613,15 @@ func (p *cgoPackage) makeASTType(typ C.CXType, pos token.Pos) ast.Expr { } } if typeName == "" { + // Report this as an error. + spelling := getString(C.clang_getTypeSpelling(typ)) + p.errors = append(p.errors, scanner.Error{ + Pos: p.fset.PositionFor(pos, true), + Msg: fmt.Sprintf("unknown C type: %v (libclang type kind %d)", spelling, typ.kind), + }) // Fallback, probably incorrect but at least the error points to an odd // type name. - typeName = "C." + getString(C.clang_getTypeSpelling(typ)) + typeName = "C." + spelling } return &ast.Ident{ NamePos: pos, |