You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=iotabc=b*2d=c*time.Seconde=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 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.
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, like3 * time.Second
, not like3e9
).The crux of the issue was being able to identify, for a constant expression, where/how its components were defined.
For example, given:
I'd like to be able to trace from
e
all the way back to the other expressions from whiche
'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
The text was updated successfully, but these errors were encountered: