Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 885f1cb

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
Fix constant folding of type literal equality
Closes #35853 Change-Id: I1c6caa1c8e074e8fd80c47699d6b0837bec166e0 Reviewed-on: https://dart-review.googlesource.com/c/92422 Reviewed-by: Stephen Adams <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 3638e43 commit 885f1cb

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/compiler/lib/src/constants/values.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ class TypeConstantValue extends ObjectConstantValue {
450450

451451
bool operator ==(other) {
452452
return other is TypeConstantValue &&
453-
representedType == other.representedType;
453+
representedType.unaliased == other.representedType.unaliased;
454454
}
455455

456-
int get hashCode => representedType.hashCode * 13;
456+
int get hashCode => representedType.unaliased.hashCode * 13;
457457

458458
List<ConstantValue> getDependencies() => const <ConstantValue>[];
459459

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
7+
typedef F1 = int Function(int);
8+
typedef F2 = int Function(int);
9+
typedef F3 = int Function(double);
10+
11+
@pragma('dart2js:noInline')
12+
id(x) => x;
13+
14+
main() {
15+
var f1 = F1;
16+
var f2 = F2;
17+
var f3 = F3;
18+
Expect.isTrue(f1 == f2);
19+
var result12 = identical(f1, f2);
20+
Expect.isFalse(f1 == f3);
21+
Expect.isFalse(identical(f1, f3));
22+
Expect.isFalse(f2 == f3);
23+
Expect.isFalse(identical(f2, f3));
24+
25+
var g1 = id(F1);
26+
var g2 = id(F2);
27+
var g3 = id(F3);
28+
Expect.isTrue(g1 == g2);
29+
Expect.equals(result12, identical(g1, g2));
30+
Expect.isFalse(g1 == g3);
31+
Expect.isFalse(identical(g1, g3));
32+
Expect.isFalse(g2 == g3);
33+
Expect.isFalse(identical(g2, g3));
34+
}

0 commit comments

Comments
 (0)