Description
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