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

Commit 02f0f53

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Don't block nnbd top merge on typedef types
The MergeVisitor was trying to merge FunctionType.typedefType in order to merge function types, thus preventing nnbd top merge of two compatible types that were just introduced through different typedefs or function type syntax. Change-Id: Icea75598168c86ed33314db22ebeec3e666c3675 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184785 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Dmitry Stefantsov <[email protected]>
1 parent 78db953 commit 02f0f53

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2021, 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+
/*library: nnbd=true*/
6+
7+
typedef Typedef1 = void Function();
8+
typedef Typedef2 = dynamic Function();
9+
10+
/*class: A:A,Object*/
11+
abstract class A {
12+
/*member: A.method1:void Function(void Function())*/
13+
void method1(void Function() f);
14+
15+
/*member: A.method2:void Function(void Function())*/
16+
void method2(Typedef1 f);
17+
18+
/*member: A.method3:void Function(void Function())*/
19+
void method3(Typedef1 f);
20+
21+
/*member: A.method4:void Function(void Function())*/
22+
void method4(void Function() f);
23+
}
24+
25+
/*class: B:B,Object*/
26+
abstract class B {
27+
/*member: B.method1:void Function(dynamic Function())*/
28+
void method1(dynamic Function() f);
29+
30+
/*member: B.method2:void Function(dynamic Function())*/
31+
void method2(Typedef2 f);
32+
33+
/*member: B.method3:void Function(dynamic Function())*/
34+
void method3(dynamic Function() f);
35+
36+
/*member: B.method4:void Function(dynamic Function())*/
37+
void method4(Typedef2 f);
38+
}
39+
40+
/*class: C:A,B,C,Object*/
41+
abstract class C implements A, B {
42+
/*member: C.method1:void Function(Object? Function())*/
43+
/*member: C.method2:void Function(Object? Function())*/
44+
/*member: C.method3:void Function(Object? Function())*/
45+
/*member: C.method4:void Function(Object? Function())*/
46+
}

pkg/front_end/lib/src/fasta/kernel/combined_member_signature.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ abstract class CombinedMemberSignatureBase<T> {
332332
_coreTypes,
333333
_combinedMemberSignatureType,
334334
norm(_coreTypes, getMemberType(index)));
335+
assert(
336+
_combinedMemberSignatureType != null,
337+
"No combined member signature found for "
338+
"${_mutualSubtypes.values.map((int i) => getMemberType(i))}");
335339
}
336340
}
337341
_neededNnbdTopMerge =

pkg/kernel/lib/src/merge_visitor.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ class MergeVisitor implements DartTypeVisitor1<DartType?, DartType> {
115115
newNamedParameters[i] = newNamedType;
116116
}
117117
TypedefType? newTypedefType;
118-
if (a.typedefType != null) {
118+
if (a.typedefType != null && b.typedefType != null) {
119119
newTypedefType = mergeTypes(a.typedefType, b.typedefType) as TypedefType?;
120-
if (newTypedefType == null) return null;
120+
// If the typedef couldn't be merged we just omit it from the resulting
121+
// function type since the typedef type is only informational.
121122
}
122123

123124
return new FunctionType(newPositionalParameters, newReturnType, nullability,

0 commit comments

Comments
 (0)