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

go/types: export a function for representability #28267

Closed
jba opened this issue Oct 18, 2018 · 6 comments
Closed

go/types: export a function for representability #28267

jba opened this issue Oct 18, 2018 · 6 comments
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@jba
Copy link
Contributor

jba commented Oct 18, 2018

Export something like the representableConst function for testing whether a constant.Value is representable by a type.

My use case: I'm writing an API compatibility checker, and I want to report whether a changed constant value can still be used with all the types that it was previously.

@ALTree ALTree added FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 18, 2018
@ALTree ALTree added this to the Go1.12 milestone Oct 18, 2018
@mvdan
Copy link
Member

mvdan commented Oct 18, 2018

@jba I presume you meant this for go/types?

/cc @griesemer

@griesemer
Copy link
Contributor

@jba I think you can already do that with a little bit of code: go/types already exports AssignableTo and ConvertibleTo. It really depends on how the constant is being used. And whether it has a type. But these functions should suffice. (I can also export RepresentableBy, but it's not clear it's needed).

As an aside, I assume you're also looking at the existing API checker we have in the std lib for guidance? There's an awful lot of details that you don't want to re-invent, ideally.

@jba jba changed the title go/tools: export a function for representability go/types: export a function for representability Oct 19, 2018
@jba
Copy link
Contributor Author

jba commented Oct 19, 2018

Yes, sorry, go/types. I edited the issue title.

I don't see how those functions could help, since they both take only types.
const c1 = 1 and const c2 = -1 have the same type, so asking if that type is assignable to uint8 must give the same answer for both. But var u uint8 = c1 compiles while var u uint8 = c2 doesn't.

I haven't looked at the std lib checker yet. I will.

@griesemer
Copy link
Contributor

Ah, yes, I forgot that the exported AssignableTo doesn't take the value of a constant into account (the internal version operand.assignableTo does). Fair enough, seems like a reasonable request. Is this urgent (for 1.12)?

@jba
Copy link
Contributor Author

jba commented Oct 20, 2018

Not urgent.

@jba
Copy link
Contributor Author

jba commented Nov 8, 2018

I no longer need this. Closing the issue, since there are no other requests.

@jba jba closed this as completed Nov 8, 2018
@golang golang locked and limited conversation to collaborators Nov 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge 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

5 participants