@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.
changed the title
go/tools: export a function for representabilityOct 19, 2018
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.
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)?