Skip to content

Commit 69b612b

Browse files
pqcommit-bot@chromium.org
authored andcommitted
diagnostic ref fix for fall-through types
See: #38633 Change-Id: I5fd1328a5ad234e6216631007ecbcc459bfa36e9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120340 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
1 parent 8e2649b commit 69b612b

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

pkg/analysis_server/lib/src/services/correction/base_processor.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ abstract class BaseProcessor {
100100
}
101101

102102
var constructorName;
103-
var hasTypeArgs = false;
104-
if (type.isDartCoreBool) {
105-
constructorName = 'DiagnosticsProperty<bool>';
106-
} else if (type.isDartCoreInt) {
103+
var typeArgs;
104+
105+
if (type.isDartCoreInt) {
107106
constructorName = 'IntProperty';
108107
} else if (type.isDartCoreDouble) {
109108
constructorName = 'DoubleProperty';
@@ -113,15 +112,16 @@ abstract class BaseProcessor {
113112
constructorName = 'EnumProperty';
114113
} else if (isIterable(type)) {
115114
constructorName = 'IterableProperty';
116-
hasTypeArgs = true;
115+
typeArgs = (type as InterfaceType).typeArguments;
117116
} else if (flutter.isColor(type)) {
118117
constructorName = 'ColorProperty';
119118
} else if (flutter.isMatrix4(type)) {
120119
constructorName = 'TransformProperty';
121-
}
122-
123-
if (constructorName == null) {
124-
return null;
120+
} else {
121+
constructorName = 'DiagnosticsProperty';
122+
if (!type.isDynamic) {
123+
typeArgs = [type];
124+
}
125125
}
126126

127127
void writePropertyReference(
@@ -130,9 +130,9 @@ abstract class BaseProcessor {
130130
@required String builderName,
131131
}) {
132132
builder.write("$prefix$builderName.add($constructorName");
133-
if (hasTypeArgs) {
133+
if (typeArgs != null) {
134134
builder.write('<');
135-
builder.writeTypes((type as InterfaceType).typeArguments);
135+
builder.writeTypes(typeArgs);
136136
builder.write('>');
137137
}
138138
builder.writeln("('${name.name}', ${name.name}));");

pkg/analysis_server/test/src/services/correction/fix/add_diagnostic_property_reference_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ class A extends Widget {
162162
''');
163163
}
164164

165+
test_dynamicField_debugFillProperties() async {
166+
await resolveTestUnit('''
167+
class A extends Widget {
168+
dynamic /*LINT*/field;
169+
@override
170+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
171+
super.debugFillProperties(properties);
172+
}
173+
}
174+
''');
175+
await assertHasFix('''
176+
class A extends Widget {
177+
dynamic /*LINT*/field;
178+
@override
179+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
180+
super.debugFillProperties(properties);
181+
properties.add(DiagnosticsProperty('field', field));
182+
}
183+
}
184+
''');
185+
}
186+
165187
test_enumField_debugFillProperties() async {
166188
await resolveTestUnit('''
167189
enum foo {bar}
@@ -277,6 +299,28 @@ class A extends Widget {
277299
''');
278300
}
279301

302+
test_objectField_debugFillProperties() async {
303+
await resolveTestUnit('''
304+
class A extends Widget {
305+
Object /*LINT*/field;
306+
@override
307+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
308+
super.debugFillProperties(properties);
309+
}
310+
}
311+
''');
312+
await assertHasFix('''
313+
class A extends Widget {
314+
Object /*LINT*/field;
315+
@override
316+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
317+
super.debugFillProperties(properties);
318+
properties.add(DiagnosticsProperty<Object>('field', field));
319+
}
320+
}
321+
''');
322+
}
323+
280324
test_stringField_debugFillProperties() async {
281325
await resolveTestUnit('''
282326
class A extends Widget {

0 commit comments

Comments
 (0)