Skip to content

proposal: spec: disallow unused const in func body #17100

@zimmski

Description

@zimmski

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions