mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 23:43:40 +00:00
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).
This commit is contained in:
committed by
Ron Evans
parent
dfa713040a
commit
7ada00790c
+7
-1
@@ -613,9 +613,15 @@ func (p *cgoPackage) makeASTType(typ C.CXType, pos token.Pos) ast.Expr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeName == "" {
|
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
|
// Fallback, probably incorrect but at least the error points to an odd
|
||||||
// type name.
|
// type name.
|
||||||
typeName = "C." + getString(C.clang_getTypeSpelling(typ))
|
typeName = "C." + spelling
|
||||||
}
|
}
|
||||||
return &ast.Ident{
|
return &ast.Ident{
|
||||||
NamePos: pos,
|
NamePos: pos,
|
||||||
|
|||||||
Reference in New Issue
Block a user