Files
sdk/runtime/tests/vm/dart/regress_flutter20122_test.dart
T
Vyacheslav Egorov c5f933fdf7 [vm/lib] String._identityHashCode should be the same as String.get:hashCode
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>
2018-08-02 11:24:25 +00:00

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);
}