[Refactoring] Don't crash when converting a function to async that contains a call to init

We were trying to retrieve the name of all function calls in the body using `getBaseIdentifier`. But calls to `init` don’t have a base identifier, just a `DeclBaseName` (which is special). Work with the `DeclBaseName` internally to prevent the crash.

Fixes rdar://78024731 [SR-14637]
This commit is contained in:
Alex Hoppen
2021-05-31 12:13:07 +02:00
parent bb6b2712e4
commit 58be2bfbea
2 changed files with 18 additions and 6 deletions

View File

@@ -844,3 +844,15 @@ func testPreserveComments3() {
// PRESERVE-TRAILING-COMMENT-CALL: let s = await simple()
// PRESERVE-TRAILING-COMMENT-CALL-NEXT: print(s)
// PRESERVE-TRAILING-COMMENT-CALL-NOT: // make sure we pickup this trailing comment if we're converting the function, but not the call
class TestConvertFunctionWithCallToFunctionsWithSpecialName {
required init() {}
subscript(index: Int) -> Int { return index }
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):3
static func example() -> Self {
let x = self.init()
_ = x[1]
return x
}
}