Files
swift-mirror/test/refactoring/ConvertToSwitchStmt/enum_with_raw_value.swift
Alex Hoppen e835c4a031 [Refactoring] Fix a crash that occurred when converting if/else of enum with raw value to switch statement
If the enum has a raw value, `E` passed in to `BinaryExpr` is a `DeclRefExpr`, not a `DotSyntaxCallExpr`, so we crashed on `dyn_cast<DotSyntaxCallExpr>(E->getFn())->getFn()`.

Only look through `DotSyntaxCallExpr` if `E` is indeed a `DotSyntaxCallExpr`. While at it, fix a few other potential sources of nullptr crashes.

rdar://84707973
2022-05-02 15:52:24 +02:00

23 lines
558 B
Swift

enum EnumWithUnderlyingValue: String {
case north, south, east, west
}
func foo(test: EnumWithUnderlyingValue) {
if test == .north {
print("north")
} else if test == .south {
print("south")
} else if test == .east {
print("east")
}
}
// RUN: %empty-directory(%t.result)
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=8:3 -end-pos=14:4 > %t.result/L8-3.swift
// RUN: %target-swift-frontend-typecheck %t.result/L8-3.swift
// RUN: diff -u %S/Outputs/enum_with_raw_value/L8-3.swift.expected %t.result/L8-3.swift