unnecessary_ this_ alias
Details about the 'unnecessary_this_alias' diagnostic produced by the Dart analyzer.
Unnecessary 'this' alias.
Description
#
The analyzer produces this diagnostic when a local variable is initialized
to this and the variable is only used in ways that could just use this.
Example
#
The following code produces this diagnostic because the local variable self
is initialized to this, is never reassigned, and its only usage is a promotion
check that could be performed on this directly under the this-promotion
feature:
class C {
void m() {
var self = this;
if (self is D) {
// ...
}
}
}
class D extends C {}
Common fixes
#Remove the local variable and use this directly:
class C {
void m() {
if (this is D) {
// ...
}
}
}
class D extends C {}
Unless stated otherwise, the documentation on this site reflects Dart 3.12.2. Report an issue.