Color operator== should compare runtimeTypes (flutter/engine#3495)

This commit is contained in:
Hans Muller
2017-03-22 10:58:03 -07:00
committed by GitHub
parent 0027d03af9
commit 6a452f9ebd
2 changed files with 17 additions and 1 deletions

View File

@@ -170,7 +170,9 @@ class Color {
@override
bool operator ==(dynamic other) {
if (other is! Color)
if (identical(this, other))
return true;
if (other.runtimeType != runtimeType)
return false;
final Color typedOther = other;
return value == typedOther.value;

View File

@@ -6,6 +6,10 @@ import 'dart:ui';
import 'package:test/test.dart';
class NotAColor extends Color {
const NotAColor(int value) : super(value);
}
void main() {
test("color accessors should work", () {
Color foo = const Color(0x12345678);
@@ -41,4 +45,14 @@ void main() {
expect(e != null, equals(true));
}
});
test("two colors are only == if they have the same runtime type", () {
expect(const Color(123), equals(const Color(123)));
expect(const Color(123), equals(new Color(123)));
expect(const Color(123), isNot(equals(const Color(321))));
expect(const Color(123), isNot(equals(const NotAColor(123))));
expect(const NotAColor(123), isNot(equals(const Color(123))));
expect(const NotAColor(123), equals(const NotAColor(123)));
});
}