Skip to content

Commit 3382418

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Disallow inlining SDK code
Fixes #60308 Change-Id: Ic813b309f57464f16e3285e594ec4ec18f14f4e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442120 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent d6a666b commit 3382418

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ class InlineMethodRefactoringImpl extends RefactoringImpl
303303
}
304304
var methodElement = _methodElement!;
305305

306+
// Disallow inlining SDK code.
307+
if (methodElement.library.isInSdk) {
308+
result = RefactoringStatus.fatal("Can't inline SDK code.");
309+
return result;
310+
}
311+
306312
// Disallow inlining an augmented method.
307313
var methodFragment = methodElement.firstFragment;
308314
if (methodFragment.nextFragment != null) {

pkg/analysis_server/test/services/refactoring/legacy/inline_method_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ void f() {
351351
return _assertConditionsFatal("Can't inline a class method reference.");
352352
}
353353

354+
Future<void> test_bad_sdkCode() async {
355+
await indexTestUnit(r'''
356+
void f() {
357+
print('');
358+
}
359+
''');
360+
_createRefactoring('print');
361+
// error
362+
return _assertInvalidSelectionSdkCode();
363+
}
364+
354365
Future<void> test_bad_severalReturns() async {
355366
await indexTestUnit(r'''
356367
test() {
@@ -2267,6 +2278,10 @@ class _InlineMethodTest extends RefactoringTest {
22672278
);
22682279
}
22692280

2281+
Future<void> _assertInvalidSelectionSdkCode() {
2282+
return _assertConditionsFatal("Can't inline SDK code.");
2283+
}
2284+
22702285
Future<void> _assertSuccessfulRefactoring(String expectedCode) async {
22712286
var status = await refactoring.checkInitialConditions();
22722287
assertRefactoringStatusOK(status);

0 commit comments

Comments
 (0)