Fix an invalid null check in InlineMethodRefactoring.

Saw it failing in the crash log.

Change-Id: I6cf715aeb6f41e405af58a00b69b8742fd7c5ed0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214182
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-09-22 17:53:10 +00:00 committed by commit-bot@chromium.org
parent 9854a04210
commit 31922b8c57
2 changed files with 20 additions and 7 deletions

View file

@ -147,7 +147,8 @@ Set<String> _getNamesConflictingAt(AstNode node) {
// local variables and functions
{
var localsRange = _getLocalsConflictingRange(node);
var enclosingExecutable = getEnclosingExecutableNode(node)!;
var enclosingExecutable = getEnclosingExecutableNode(node);
if (enclosingExecutable != null) {
var visibleRangeMap = VisibleRangesComputer.forNode(enclosingExecutable);
visibleRangeMap.forEach((element, elementRange) {
if (elementRange.intersects(localsRange)) {
@ -155,6 +156,7 @@ Set<String> _getNamesConflictingAt(AstNode node) {
}
});
}
}
// fields
{
var enclosingClassElement = getEnclosingClassElement(node);

View file

@ -1739,6 +1739,17 @@ void f(bool p, bool p2, bool p3) {
''');
}
Future<void> test_target_topLevelVariable() async {
await indexTestUnit(r'''
int get test => 42;
var a = test;
''');
_createRefactoring('test =>');
return _assertSuccessfulRefactoring(r'''
var a = 42;
''');
}
Future _assertConditionsError(String message) async {
var status = await refactoring.checkAllConditions();
assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,