blob: e29c9658c39369d1fc8a9ac0541ae35c1db99efd [file] [log] [blame]
// Copyright (c) 2019, 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/ `pub run test -N avoid_equals_and_hash_code_on_mutable_classes`
// Hack to work around issues importing `meta.dart` in tests.
// Ideally, remove:
library meta;
class _Immutable {
const _Immutable();
}
const _Immutable immutable = _Immutable();
@immutable
class A {
final String key;
const A(this.key);
@override
operator ==(other) => other is A && other.key == key; // OK
@override
int hashCode() => key.hashCode; // OK
}
class B {
final String key;
const B(this.key);
@override
operator ==(other) => other is B && other.key == key; // LINT
@override
int hashCode() => key.hashCode; // LINT
}
@immutable
class C {
const C();
}
class D extends C {
final String key;
const D(this.key);
@override
operator ==(other) => other is B && other.key == key; // OK
@override
int get hashCode => key.hashCode; // OK
}