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: whence this constant value? #11455

Closed
josharian opened this issue Jun 29, 2015 · 2 comments
Closed

go/types: whence this constant value? #11455

josharian opened this issue Jun 29, 2015 · 2 comments

Comments

@josharian
Copy link
Contributor

I attempted and ultimately failed to write a lint check that analyzed time.Duration constants, to ensure that they were defined using a unit (that is, like 3 * time.Second, not like 3e9).

The crux of the issue was being able to identify, for a constant expression, where/how its components were defined.

For example, given:

const (
  a = iota
  b
  c = b * 2
  d = c * time.Second
  e = d - 1
)

I'd like to be able to trace from e all the way back to the other expressions from which e's value is derived. This might extend across files and packages. As far as I can tell, there's no reasonable way to get this information now. But this information must be available during typechecking.

This is not a high priority, and there are obviously API questions. Just putting this on the wishlist. :)

/cc @griesemer @alandonovan

@alandonovan
Copy link
Contributor

On 28 June 2015 at 23:23, Josh Bleecher Snyder notifications@github.com
wrote:

I attempted
golang/lint@b550591
and ultimately failed
golang/lint@4946cea
to write a lint check golang/lint#130 that
analyzed time.Duration constants, to ensure that they were defined using
a unit (that is, like 3 * time.Second, not like 3e9).

The crux of the issue was being able to identify, for a constant
expression, where/how its components were defined.

For example, given:

const (
a = iota
b
c = b * 2
d = c * time.Second
e = d - 1
)

I'd like to be able to trace from e all the way back to the other
expressions from which e's value is derived. This might extend across
files and packages. As far as I can tell, there's no reasonable way to get
this information now. But this information must be available during
typechecking.

This is not a high priority, and there are obviously API questions. Just
putting this on the wishlist. :)

I responded on the 'ultimately failed' bug ticket, but I think the general
answer here is: the type checker API provides you with all the building
blocks you need, and it cannot provide more without (a) redundancy and (b)
sacrificing the ability to load packages without source code.

If you're still stuck next week, we can work on it together at GopherCon if
you like.

@josharian
Copy link
Contributor Author

Thanks, that's very useful. I think I see the way forward.

@golang golang locked and limited conversation to collaborators Jun 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants