mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:21:18 +00:00
1c8d65c49b
This change expands typedefs into their underlying function type in the compiler. Typedefs no longer exist at runtime in DDC, so they now have similar equality and identity behavior as other function types. The compiler used to preserve typedefs so they could have a better toString. But over time that support has been almost entirely lost; the caching for function/interface types eliminates typedefs, and DDC+Kernel does not appear to get any TypedefTypes from the common front end. So in practice typedef types were almost never present at runtime. Because of this, we can remove the remaining support with very little user visible effect. This also brings DDC's canonicalization roughly in line with dart2js for compile-time typedefs, so frameworks like Angular will be able to continue their use of `identical` for fast type comparisons. This CL also fixes DDC's type caching for generic function types (typeHashCode was incorrect for them), and has some refactoring to improve names/comments and make the SDK runtime code more clear. Change-Id: I4e34c0c8f737a8535ba474a4683967ff41bcd3c8 Reviewed-on: https://dart-review.googlesource.com/74664 Commit-Queue: Jenny Messerly <jmesserly@google.com> Reviewed-by: Alan Knight <alanknight@google.com>
25 lines
763 B
Dart
25 lines
763 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.
|
|
|
|
// Test that type aliases perform equality tests according to the
|
|
// underlying function type, not as if they were a distinct type
|
|
// for each type alias declaration.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
typedef F1 = void Function(int);
|
|
typedef F2 = void Function(int);
|
|
typedef void F3(int x);
|
|
|
|
typedef G1 = X Function<X>(X);
|
|
typedef G2 = X Function<X>(X);
|
|
typedef G3 = Y Function<Y>(Y);
|
|
|
|
main() {
|
|
Expect.equals(F1, F2); //# 01: ok
|
|
Expect.equals(F1, F3); //# 02: ok
|
|
Expect.equals(G1, G2); //# 03: ok
|
|
Expect.equals(G1, G3); //# 04: ok
|
|
}
|