mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Use it to provide an idealized API for the VarDecl case in validateDecl. In reality, a lot of work is needed to rationalize the dependency structure of this request. To start, the callers of typeCheckPatternBinding must be eliminated piecemeal. Once that is done, the AST should introduce pattern binding decls along all the places where getParentStmt() used to apply.
31 lines
1.4 KiB
Swift
31 lines
1.4 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
var a: Int = nil
|
|
// expected-error@-1 {{'nil' cannot initialize specified type 'Int'}}
|
|
// expected-note@-2 {{add '?' to form the optional type 'Int?'}} {{11-11=?}}
|
|
|
|
var b: () -> Void = nil
|
|
// expected-error@-1 {{'nil' cannot initialize specified type '() -> Void'}}
|
|
// expected-note@-2 {{add '?' to form the optional type '(() -> Void)?'}} {{8-8=(}} {{18-18=)?}}
|
|
|
|
var c, d: Int = nil
|
|
// expected-error@-1 {{type annotation missing in pattern}}
|
|
// expected-error@-2 {{'nil' cannot initialize specified type 'Int'}}
|
|
// expected-note@-3 {{add '?' to form the optional type 'Int?'}} {{14-14=?}}
|
|
|
|
var (e, f): (Int, Int) = nil
|
|
// expected-error@-1 {{'nil' cannot initialize specified type '(Int, Int)'}}
|
|
|
|
var g: Int = nil, h: Int = nil
|
|
// expected-error@-1 {{'nil' cannot initialize specified type 'Int'}}
|
|
// expected-note@-2 {{add '?' to form the optional type 'Int?'}} {{11-11=?}}
|
|
// expected-error@-3 {{'nil' cannot initialize specified type 'Int'}}
|
|
// expected-note@-4 {{add '?' to form the optional type 'Int?'}} {{25-25=?}}
|
|
|
|
var _: Int = nil
|
|
// expected-error@-1 {{'nil' cannot initialize specified type 'Int'}}
|
|
// expected-note@-2 {{add '?' to form the optional type 'Int?'}} {{11-11=?}}
|
|
|
|
// 'nil' can initialize the specified type, if its generic parameters are bound
|
|
var _: Array? = nil // expected-error {{generic parameter 'Element' could not be inferred}}
|