mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When we determine that an optional value needs to be unwrapped to make
an expression type check, use notes to provide several different
Fix-It options (with descriptions) rather than always pushing users
toward '!'. Specifically, the errors + Fix-Its now looks like this:
error: value of optional type 'X?' must be unwrapped to a value of
type 'X'
f(x)
^
note: coalesce using '??' to provide a default when the optional
value contains 'nil'
f(x)
^
?? <#default value#>
note: force-unwrap using '!' to abort execution if the optional
value contains 'nil'
f(x)
^
!
Fixes rdar://problem/42081852.
27 lines
641 B
Swift
27 lines
641 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -typecheck -primary-file %s -module-cache-path %t/mcp -emit-remap-file-path %t/edits.remap -swift-version 3
|
|
// RUN: %FileCheck %s -input-file=%t/edits.remap
|
|
|
|
enum SomeStringEnum : String {
|
|
case val = ""
|
|
}
|
|
|
|
#if swift(>=4)
|
|
func foo() {
|
|
let e : SomeStringEnum = "aa"
|
|
}
|
|
#endif
|
|
|
|
// CHECK:[
|
|
// CHECK: {
|
|
// CHECK: "file": "{{.*}}rdar31892850.swift",
|
|
// CHECK: "offset": 323,
|
|
// CHECK: "text": "SomeStringEnum(rawValue: "
|
|
// CHECK: },
|
|
// CHECK: {
|
|
// CHECK: "file": "{{.*}}rdar31892850.swift",
|
|
// CHECK: "offset": 327,
|
|
// CHECK: "text": ")"
|
|
// CHECK: }
|
|
// CHECK:]
|