mdempsky/unconvert

false positives in cgo generated expressions

mdempsky opened this issue · 2 comments

cgo rewrites code like:

return statusToError(C.DBIterError(r.iter))

to:

    return statusToError(_Cfunc_DBIterError(_cgoCheckPointer((*_Ctype_struct_DBIterator)(r.iter)).(*_Ctype_struct_DBIterator)))

In this case, r.iter is already of type *_Ctype_struct_DBIterator, and the conversion didn't exist in the original source, so we shouldn't warn about it.

Repro with unconvert github.com/cockroachdb/cockroach/storage/engine.

Alternatively, is this an improvement that can be made in cgo itself?

@tamird Possibly. I actually think the conversions are technically erroneous anyway (they're only enforcing that pointer arguments to C functions are convertible to their corresponding parameter types, whereas for consistency with the Go language they should be required to be assignable), but I think it's easy enough to just fix in unconvert.