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

Comments

@jba
Copy link
Contributor

@jba 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.

@mvdan
Copy link
Member

@mvdan mvdan commented Oct 18, 2018

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

/cc @griesemer

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 18, 2018

@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.

Loading

@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 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.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 19, 2018

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)?

Loading

@jba
Copy link
Contributor Author

@jba jba commented Oct 20, 2018

Not urgent.

Loading

@jba
Copy link
Contributor Author

@jba jba commented Nov 8, 2018

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

Loading

@jba jba closed this 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants