Skip to content

Commit cc876c2

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes infering bool for guard in create fixes
Fixes: #61589 Change-Id: Iaf43927c9d3fcf43b2dfa23c91e17333baeed184 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452181 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent aeb3a58 commit cc876c2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,25 @@ void f(A a) {
261261
''');
262262
}
263263

264+
Future<void> test_guard() async {
265+
await resolveTestCode('''
266+
class A {
267+
void f(Object? x) {
268+
if (x case String() when getter) {}
269+
}
270+
}
271+
''');
272+
await assertHasFix('''
273+
class A {
274+
bool get getter => null;
275+
276+
void f(Object? x) {
277+
if (x case String() when getter) {}
278+
}
279+
}
280+
''');
281+
}
282+
264283
Future<void> test_hint_getter() async {
265284
await resolveTestCode('''
266285
class A {

pkg/analysis_server_plugin/lib/edit/dart/correction_producer.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,12 @@ abstract class ResolvedCorrectionProducer
658658
return _coreTypeBool;
659659
}
660660
}
661+
if (parent is WhenClause) {
662+
var clause = parent;
663+
if (clause.expression == expression) {
664+
return _coreTypeBool;
665+
}
666+
}
661667
// `while ( myFunction() ) {}`.
662668
if (parent is WhileStatement) {
663669
var statement = parent;

0 commit comments

Comments
 (0)