Skip to content

[Feature Request]: more linter rules for initializers #26171

Open
@jabraham17

Description

@jabraham17

Part of the future work from #26115 is to expose InitResolver to chapel-py. This would improve the linting logic for that rule, but would also open opportunities for other rules.

The first thing that comes to mind is something like the following

record R {
  var x: int;
  proc init(in x: int) {
    this.x = 1;
    this.x = x;
    init this;
  }
}

this.x is initialized twice, and the compiler accepts this as valid code. However, the line this.x = 1 is useless and the backend should optimize it away as part of DSE.

However, this isn't great Chapel code and I think it would be good to have a linter warning for this.x = 1, something like "variable initialized twice" or "useless initialization statement"

Another case demonstrated by this code sample is this init this at the end of the initializer, which is technically not needed. We could also have a linter warning for "useless init this".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      [Feature Request]: more linter rules for initializers · Issue #26171 · chapel-lang/chapel