mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Expand the special-cased ASTWalker behavior for folded SequenceExprs such that we always walk the folded expression when available. This ensures that we don't attempt to add the same node multiple times when expanding ASTScopes during pre-checking. rdar://147751795
37 lines
1.4 KiB
Swift
37 lines
1.4 KiB
Swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
func testDictionary() {
|
|
// -[NSDictionary init] returns non-nil.
|
|
var dictNonOpt = NSDictionary()
|
|
_ = dictNonOpt! // expected-error {{cannot force unwrap value of non-optional type 'NSDictionary'}}
|
|
}
|
|
|
|
func testString() throws {
|
|
// Optional
|
|
let stringOpt = NSString(path: "blah", encoding: 0)
|
|
// expected-note@-1 {{short-circuit using 'guard' to exit this function early if the optional value contains 'nil'}}
|
|
// expected-note@-2 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
|
|
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
|
|
|
|
_ = stringOpt as NSString // expected-error{{value of optional type 'NSString?' must be unwrapped to a value of type 'NSString'}}
|
|
// expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
|
|
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
|
|
|
|
// Implicitly unwrapped optional
|
|
let stringIUO = NSString(path: "blah")
|
|
if stringIUO == nil { }
|
|
_ = stringIUO as NSString?
|
|
let _: NSString = NSString(path: "blah")
|
|
}
|
|
|
|
func testHive() {
|
|
let hiveIUO = Hive()
|
|
if hiveIUO == nil { }
|
|
_ = hiveIUO as Hive?
|
|
let _: Hive = Hive()
|
|
}
|