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

Commit 494cd25

Browse files
author
Dart CI
committed
Version 2.13.0-42.0.dev
Merge commit '4d5f027ccb2d998771677067a621bdd582ddfaf6' into 'dev'
2 parents fc4360f + 4d5f027 commit 494cd25

File tree

5 files changed

+137
-9
lines changed

5 files changed

+137
-9
lines changed

pkg/analysis_server/test/src/domains/completion/get_suggestion_details_test.dart

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,104 @@ main() {} // ref
111111
_assertTestFileChange(result.change, r'''
112112
import 'dart:math';
113113
114+
main() {} // ref
115+
''');
116+
}
117+
118+
Future<void> test_newImport_afterLibraryBeforeFirstImportsAnnotation() async {
119+
// Annotations are only treated as being for the file if they are on the first
120+
// directive of the file.
121+
addTestFile(r'''
122+
library foo;
123+
124+
@myAnnotation
125+
import 'package:zzz';
126+
127+
main() {} // ref
128+
''');
129+
130+
var mathSet = await waitForSetWithUri('dart:math');
131+
var result = await _getSuggestionDetails(
132+
_buildRequest(
133+
id: mathSet.id,
134+
label: 'sin',
135+
offset: testCode.indexOf('} // ref'),
136+
),
137+
);
138+
139+
expect(result.completion, 'sin');
140+
_assertTestFileChange(result.change, r'''
141+
library foo;
142+
143+
import 'dart:math';
144+
145+
@myAnnotation
146+
import 'package:zzz';
147+
148+
main() {} // ref
149+
''');
150+
}
151+
152+
Future<void> test_newImport_betweenAnnotationAndFirstImport() async {
153+
// Annotations attached to the first import in a file are considered
154+
// to be for the file, so if an import is inserted in the top position, it
155+
// should go after the annotation.
156+
addTestFile(r'''
157+
@myAnnotation
158+
159+
import 'package:zzz';
160+
161+
main() {} // ref
162+
''');
163+
164+
var mathSet = await waitForSetWithUri('dart:math');
165+
var result = await _getSuggestionDetails(
166+
_buildRequest(
167+
id: mathSet.id,
168+
label: 'sin',
169+
offset: testCode.indexOf('} // ref'),
170+
),
171+
);
172+
173+
expect(result.completion, 'sin');
174+
_assertTestFileChange(result.change, r'''
175+
@myAnnotation
176+
177+
import 'dart:math';
178+
179+
import 'package:zzz';
180+
181+
main() {} // ref
182+
''');
183+
}
184+
185+
Future<void> test_newImport_notBetweenAnnotationAndNonFirstImport() async {
186+
// Annotations on non-first directives should not be kept above the newly
187+
// imported imports (opposite of test_newImport_betweenAnnotationAndFirstImport).
188+
addTestFile(r'''
189+
import 'dart:async';
190+
@myAnnotation
191+
import 'package:zzz';
192+
193+
main() {} // ref
194+
''');
195+
196+
var mathSet = await waitForSetWithUri('dart:math');
197+
var result = await _getSuggestionDetails(
198+
_buildRequest(
199+
id: mathSet.id,
200+
label: 'sin',
201+
offset: testCode.indexOf('} // ref'),
202+
),
203+
);
204+
205+
expect(result.completion, 'sin');
206+
_assertTestFileChange(result.change, r'''
207+
import 'dart:async';
208+
import 'dart:math';
209+
@myAnnotation
210+
import 'package:zzz';
211+
114212
main() {} // ref
115213
''');
116214
}

pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,14 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
15151515
writeImport(builder, import);
15161516
});
15171517
} else {
1518-
var offset = next.offset;
1518+
// Annotations attached to the first directive should remain above
1519+
// the newly inserted import, as they are treated as being for the
1520+
// file.
1521+
var isFirst =
1522+
next == (next.parent as CompilationUnit).directives.first;
1523+
var offset = isFirst && next is AnnotatedNode
1524+
? next.firstTokenAfterCommentAndMetadata.offset
1525+
: next.offset;
15191526
addInsertion(offset, (EditBuilder builder) {
15201527
writeImport(builder, import);
15211528
builder.writeln();

runtime/vm/object.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,6 @@ intptr_t Class::ComputeNumTypeArguments() const {
31723172
// modified by finalization, only shifted to higher indices in the vector.
31733173
// The super type may not even be resolved yet. This is not necessary, since
31743174
// we only check for matching type parameters, which are resolved by default.
3175-
const auto& type_params = TypeArguments::Handle(zone, type_parameters());
31763175
// Determine the maximum overlap of a prefix of the vector consisting of the
31773176
// type parameters of this class with a suffix of the vector consisting of the
31783177
// type arguments of the super type of this class.
@@ -3181,20 +3180,26 @@ intptr_t Class::ComputeNumTypeArguments() const {
31813180
// Attempt to overlap the whole vector of type parameters; reduce the size
31823181
// of the vector (keeping the first type parameter) until it fits or until
31833182
// its size is zero.
3184-
auto& type_param = TypeParameter::Handle(zone);
31853183
auto& sup_type_arg = AbstractType::Handle(zone);
31863184
for (intptr_t num_overlapping_type_args =
31873185
(num_type_params < sup_type_args_length) ? num_type_params
31883186
: sup_type_args_length;
31893187
num_overlapping_type_args > 0; num_overlapping_type_args--) {
31903188
intptr_t i = 0;
31913189
for (; i < num_overlapping_type_args; i++) {
3192-
type_param ^= type_params.TypeAt(i);
3193-
ASSERT(!type_param.IsNull());
31943190
sup_type_arg = sup_type_args.TypeAt(sup_type_args_length -
31953191
num_overlapping_type_args + i);
31963192
ASSERT(!sup_type_arg.IsNull());
3197-
if (!type_param.Equals(sup_type_arg)) break;
3193+
if (!sup_type_arg.IsTypeParameter()) break;
3194+
// The only type parameters appearing in the type arguments of the super
3195+
// type are those declared by this class. Their finalized indices depend
3196+
// on the number of type arguments being computed here. Therefore, they
3197+
// cannot possibly be finalized yet.
3198+
ASSERT(!TypeParameter::Cast(sup_type_arg).IsFinalized());
3199+
if (TypeParameter::Cast(sup_type_arg).index() != i ||
3200+
TypeParameter::Cast(sup_type_arg).IsNullable()) {
3201+
break;
3202+
}
31983203
}
31993204
if (i == num_overlapping_type_args) {
32003205
// Overlap found.
@@ -21033,12 +21038,12 @@ bool TypeParameter::IsEquivalent(const Instance& other,
2103321038
return false;
2103421039
}
2103521040
const TypeParameter& other_type_param = TypeParameter::Cast(other);
21041+
ASSERT(IsFinalized() && other_type_param.IsFinalized());
2103621042
// Compare index, name, bound, default argument, and flags.
2103721043
if (IsFunctionTypeParameter()) {
2103821044
if (!other_type_param.IsFunctionTypeParameter()) {
2103921045
return false;
2104021046
}
21041-
ASSERT(IsFinalized() && other_type_param.IsFinalized());
2104221047
if (kind == TypeEquality::kInSubtypeTest) {
2104321048
// To be equivalent, the function type parameters should be declared
2104421049
// at the same position in the generic function. Their index therefore
@@ -21105,7 +21110,6 @@ bool TypeParameter::IsEquivalent(const Instance& other,
2110521110
return false;
2110621111
}
2110721112
} else {
21108-
ASSERT(IsFinalized() && other_type_param.IsFinalized());
2110921113
if (index() != other_type_param.index()) {
2111021114
return false;
2111121115
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Regression test for issue 179942377.
6+
7+
import 'package:expect/expect.dart';
8+
9+
class A<T> {
10+
bool test() {
11+
return null is T;
12+
}
13+
}
14+
15+
class B<T> extends A<T?> {}
16+
17+
void main() {
18+
Expect.isTrue(B<int>().test());
19+
}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 13
2929
PATCH 0
30-
PRERELEASE 41
30+
PRERELEASE 42
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)