mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
be aware of cascades when scraping type params for var
replacement
Fixes: https://github.com/dart-lang/sdk/issues/44156 Change-Id: I5ceb69d4a3fa4bbc68cdb7af2f9eb065ac8ae0f4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171627 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
e205acb506
commit
c84ada0fd4
|
@ -42,6 +42,9 @@ class ReplaceWithVar extends CorrectionProducer {
|
|||
String typeArgumentsText;
|
||||
int typeArgumentsOffset;
|
||||
if (type is NamedType && type.typeArguments != null) {
|
||||
if (initializer is CascadeExpression) {
|
||||
initializer = (initializer as CascadeExpression).target;
|
||||
}
|
||||
if (initializer is TypedLiteral) {
|
||||
if (initializer.typeArguments == null) {
|
||||
typeArgumentsText = utils.getNodeText(type.typeArguments);
|
||||
|
|
|
@ -74,6 +74,21 @@ void f(List<int> list) {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_generic_instanceCreation_cascade() async {
|
||||
await resolveTestCode('''
|
||||
Set f() {
|
||||
Set<String> s = Set<String>()..addAll([]);
|
||||
return s;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
Set f() {
|
||||
var s = Set<String>()..addAll([]);
|
||||
return s;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_generic_instanceCreation_withArguments() async {
|
||||
await resolveTestCode('''
|
||||
C<int> f() {
|
||||
|
@ -193,6 +208,21 @@ Set f() {
|
|||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_generic_setLiteral_cascade() async {
|
||||
await resolveTestCode('''
|
||||
Set f() {
|
||||
Set<String> s = {}..addAll([]);
|
||||
return s;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
Set f() {
|
||||
var s = <String>{}..addAll([]);
|
||||
return s;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_generic_setLiteral_const() async {
|
||||
await resolveTestCode('''
|
||||
String f() {
|
||||
|
|
Loading…
Reference in a new issue