blob: 079ef70c0e2d38ada3dfe0e8b8427cf2915c5e45 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// test w/ `dart test -N avoid_null_checks_in_equality_operators`
class BadPerson1 {
final String name = 'I am a bad person';
get age => 42;
@override
operator ==(other) =>
other != null && // LINT
other is BadPerson1 &&
name == other.name;
}
class BadPerson2 {
final String name = 'I am a bad person';
@override
operator ==(other) =>
!(other == null) && // LINT
other is BadPerson2 &&
name == other.name;
}
class BadPerson3 {
final String name = 'I am a bad person';
@override
operator ==(other) =>
other is BadPerson3
&&
name == other?.name; // LINT
}
class BadPerson4 {
final String name = 'I am a bad person';
String getName() => name;
@override
operator ==(other) =>
other is BadPerson4
&&
name == other?.getName(); // LINT
}
class BadPerson5 {
String name;
BadPerson5(this.name);
@override
operator ==(other) {
if (other is BadPerson5){
final toCompare = other ?? new BadPerson5(""); // LINT
return toCompare.name == name;
}
return false;
}
}
class GoodPerson {
final String name = 'I am a good person';
@override
operator ==(other) => other is GoodPerson && name == other.name; // OK
}