-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
In retrospective to the discussion on golang-nuts https://groups.google.com/forum/#!topic/golang-nuts/F1KskeC2IdU I want to propose (I guess this should get the GO2 label) that it should be illegal to declare a constant inside a function body if the constant is never used.
E.g. this example https://play.golang.org/p/JG9dSa_VKg with an unused constant inside a function body should have a compile error "x declared and not used" like https://play.golang.org/p/KLzHVO5L7q has for an unused variable.
Such compile errors do already exist as is shown for variables, as well as for imports and labels. However, constants are at currently the exception. Even though there is an accepted explanation to why such usages are forbidden: "... Go refuses to compile programs with unused variables or imports, trading short-term convenience for long-term build speed and program clarity." [https://golang.org/doc/faq#unused_variables_and_imports]