Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: erroneously allows methods declared on C types #39205

Closed
mdempsky opened this issue May 21, 2020 · 1 comment
Closed

cmd/cgo: erroneously allows methods declared on C types #39205

mdempsky opened this issue May 21, 2020 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@mdempsky
Copy link
Member

As reported at #35721 (comment), this code currently builds:

package p

import "C"

func (C.int) m() {}

This is because cmd/cgo rewrites C.int into _Ctype_int, which is a valid type to declare as a receiver parameter. However, this violates the abstraction of treating "C" as a separate package, as you can't normally declare methods on types imported from other packages.

Fixing this probably just amounts to having cmd/cgo reject C.foo identifiers within receiver parameter types, but this also risks breaking existing code that relies on this.

/cc @ianlancetaylor

@mdempsky mdempsky added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 21, 2020
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@seankhliao seankhliao added this to the Unplanned milestone Aug 27, 2022
@mdempsky
Copy link
Member Author

Duplicated as #57926. (Closing in favor of that issue, because it has more discussion.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

3 participants