-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stable] Implement error about awaiting a type that is incompatible w…
…ith await This is a cherry-pick of the following 5 commits from the main branch: - Add test about types being incompatible with await (https://dart-review.googlesource.com/c/sdk/+/351143) - [cfe] Report errors on awaiting types incompatible with await (https://dart-review.googlesource.com/c/sdk/+/348640) - [cfe] Implement the update of "incompatible with await" (https://dart-review.googlesource.com/c/sdk/+/350986) - Extension type. Implement isIncompatibleWithAwait() predicate, report AWAIT_OF_INCOMPATIBLE_TYPE. (https://dart-review.googlesource.com/c/sdk/+/350986) - Extension type. Issue 54648. Fix 'incompatible with await' predicate. (https://dart-review.googlesource.com/c/sdk/+/355500) Collectively, these 5 commits implement the new "incompatible with await" error that was specified in dart-lang/language#3560 and then refined in dart-lang/language#3598. Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/348640 Cherry-pick-request: #55095 Change-Id: I84a79ffccce89c4d91c99a09ab7f5107a96e9844 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355542 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
- Loading branch information
1 parent
6dd9806
commit 662d6e1
Showing
36 changed files
with
1,638 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
pkg/analyzer/test/src/dart/element/incompatible_with_await_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
import 'package:analyzer/dart/element/type.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../../../generated/type_system_base.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(IsIncompatibleWithAwaitTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class IsIncompatibleWithAwaitTest extends AbstractTypeSystemTest { | ||
void isIncompatible(DartType type) { | ||
expect(typeSystem.isIncompatibleWithAwait(type), isTrue); | ||
} | ||
|
||
void isNotIncompatible(DartType type) { | ||
expect(typeSystem.isIncompatibleWithAwait(type), isFalse); | ||
} | ||
|
||
test_class_int() { | ||
isNotIncompatible(intNone); | ||
isNotIncompatible(intQuestion); | ||
} | ||
|
||
test_extensionType_implementsFuture() { | ||
var futureOfIntNone = futureNone(intNone); | ||
isNotIncompatible( | ||
interfaceTypeNone( | ||
extensionType( | ||
'A', | ||
representationType: futureOfIntNone, | ||
interfaces: [futureOfIntNone], | ||
), | ||
), | ||
); | ||
} | ||
|
||
test_extensionType_notImplementsFuture() { | ||
var futureOfIntNone = futureNone(intNone); | ||
|
||
isIncompatible( | ||
interfaceTypeNone( | ||
extensionType( | ||
'A', | ||
representationType: futureOfIntNone, | ||
), | ||
), | ||
); | ||
} | ||
|
||
test_futureInt() { | ||
isNotIncompatible( | ||
futureNone(intNone), | ||
); | ||
} | ||
|
||
test_futureOrInt() { | ||
isNotIncompatible( | ||
futureOrNone(intNone), | ||
); | ||
} | ||
|
||
test_typeParameter_bound_extensionType_implementsFuture() { | ||
var futureOfIntNone = futureNone(intNone); | ||
|
||
var A = extensionType( | ||
'A', | ||
representationType: futureOfIntNone, | ||
interfaces: [futureOfIntNone], | ||
); | ||
|
||
isNotIncompatible( | ||
typeParameterTypeNone( | ||
typeParameter( | ||
'T', | ||
bound: interfaceTypeNone(A), | ||
), | ||
), | ||
); | ||
} | ||
|
||
test_typeParameter_bound_extensionType_notImplementsFuture() { | ||
var futureOfIntNone = futureNone(intNone); | ||
|
||
var A = extensionType( | ||
'A', | ||
representationType: futureOfIntNone, | ||
); | ||
|
||
isIncompatible( | ||
typeParameterTypeNone( | ||
typeParameter( | ||
'T', | ||
bound: interfaceTypeNone(A), | ||
), | ||
), | ||
); | ||
} | ||
|
||
test_typeParameter_bound_numNone() { | ||
isNotIncompatible( | ||
typeParameterTypeNone( | ||
typeParameter('T', bound: numNone), | ||
), | ||
); | ||
} | ||
|
||
test_typeParameter_promotedBound_extensionType_implementsFuture() { | ||
var futureOfIntNone = futureNone(intNone); | ||
|
||
// Incompatible with `await`, used as a bound. | ||
// Does not matter, `T` is promoted to not incompatible. | ||
var N = extensionType( | ||
'N', | ||
representationType: futureOfIntNone, | ||
); | ||
|
||
var F = extensionType( | ||
'F', | ||
representationType: futureOfIntNone, | ||
interfaces: [ | ||
futureOfIntNone, | ||
], | ||
); | ||
|
||
isNotIncompatible( | ||
typeParameterTypeNone( | ||
typeParameter( | ||
'T', | ||
bound: interfaceTypeNone(N), | ||
), | ||
promotedBound: interfaceTypeNone(F), | ||
), | ||
); | ||
} | ||
|
||
test_typeParameter_promotedBound_extensionType_notImplementsFuture() { | ||
var futureOfIntNone = futureNone(intNone); | ||
|
||
var A = extensionType( | ||
'A', | ||
representationType: futureOfIntNone, | ||
); | ||
|
||
isIncompatible( | ||
typeParameterTypeNone( | ||
typeParameter('T'), | ||
promotedBound: interfaceTypeNone(A), | ||
), | ||
); | ||
} | ||
|
||
test_typeParameter_promotedBound_intNone() { | ||
isNotIncompatible( | ||
typeParameterTypeNone( | ||
typeParameter('T'), | ||
promotedBound: intNone, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
pkg/analyzer/test/src/diagnostics/await_of_extension_type_not_future_test.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.