c5f933fdf7
On 64-bit platforms we use a field in the header to cache results of Object.get:_identityHashCode. The very same field is also used to cache String.get:hashCode result. Which means that their implementations must be the same. Fixes https://github.com/flutter/flutter/issues/20122 Change-Id: I98eef9eddf833c0d7c4c6f452728fe48e232efdc Reviewed-on: https://dart-review.googlesource.com/68042 Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
25 lines
932 B
Dart
25 lines
932 B
Dart
// Copyright (c) 2018, 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.
|
|
|
|
// Regression test for https://github.com/flutter/flutter/issues/20122
|
|
// Verifies that identityHashCode for strings does not interfere
|
|
// with normal hashCode.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
var prefix = 'x';
|
|
|
|
make(v) => '${prefix}${v}'; // to inhibit constant folding.
|
|
|
|
void main() {
|
|
final x = make('test');
|
|
final y = make('test');
|
|
// On 64-bit platforms there is a field in the header that is used to cache
|
|
// hash value for both Object.get:hashCode and identityHashCode(...).
|
|
// Which means that implementation of these two methods should match
|
|
// otherwise you will get different hash codes for otherwise identical objects.
|
|
identityHashCode(y);
|
|
Expect.equals(x.hashCode, y.hashCode);
|
|
}
|