dictionary_literal.swift (swift-swift-5.8-RELEASE) | : | dictionary_literal.swift (swift-swift-5.8.1-RELEASE) | ||
---|---|---|---|---|
skipping to change at line 119 | skipping to change at line 119 | |||
a = [""] // expected-error {{dictionary of type 'T' cannot be used with array literal}} | a = [""] // expected-error {{dictionary of type 'T' cannot be used with array literal}} | |||
// expected-note@-1 {{did you mean to use a dictionary literal instead?}} {{10 -10=: <#value#>}} | // expected-note@-1 {{did you mean to use a dictionary literal instead?}} {{10 -10=: <#value#>}} | |||
} | } | |||
class A { } | class A { } | |||
class B : A { } | class B : A { } | |||
class C : A { } | class C : A { } | |||
func testDefaultExistentials() { | func testDefaultExistentials() { | |||
let _ = ["a": ["b": ["c": ["d", 1, true]]]] | ||||
let _ = ["a" : 1, "b" : 2.5, "c" : "hello"] | let _ = ["a" : 1, "b" : 2.5, "c" : "hello"] | |||
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[String : Any]'; add explicit type annotation if this is intentional}}{{46-4 6= as [String : Any]}} | // expected-error@-1{{heterogeneous collection literal could only be inferred to '[String : Any]'; add explicit type annotation if this is intentional}}{{46-4 6= as [String : Any]}} | |||
let _: [String : Any] = ["a" : 1, "b" : 2.5, "c" : "hello"] | let _: [String : Any] = ["a" : 1, "b" : 2.5, "c" : "hello"] | |||
let _ = ["a" : 1, "b" : nil, "c" : "hello"] | let _ = ["a" : 1, "b" : nil, "c" : "hello"] | |||
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[String : Any?]'; add explicit type annotation if this is intentional}}{{46- 46= as [String : Any?]}} | // expected-error@-1{{heterogeneous collection literal could only be inferred to '[String : Any?]'; add explicit type annotation if this is intentional}}{{46- 46= as [String : Any?]}} | |||
let _: [String : Any?] = ["a" : 1, "b" : nil, "c" : "hello"] | let _: [String : Any?] = ["a" : 1, "b" : nil, "c" : "hello"] | |||
let d2 = [:] | let d2 = [:] | |||
// expected-error@-1{{empty collection literal requires an explicit type}} | // expected-error@-1{{empty collection literal requires an explicit type}} | |||
let _: Int = d2 // expected-error{{value of type '[AnyHashable : Any]'}} | let _: Int = d2 // expected-error{{value of type '[AnyHashable : Any]'}} | |||
let _ = ["a": 1, | let _ = ["a": 1, | |||
"b": ["a", 2, 3.14159], | "b": ["a", 2, 3.14159], | |||
"c": ["a": 2, "b": 3.5]] | "c": ["a": 2, "b": 3.5]] | |||
// expected-error@-3{{heterogeneous collection literal could only be inferred to '[String : Any]'; add explicit type annotation if this is intentional}} | // expected-error@-3{{heterogeneous collection literal could only be inferred to '[String : Any]'; add explicit type annotation if this is intentional}} | |||
// expected-warning@-3{{heterogeneous collection literal could only be inferre d to '[Any]'; add explicit type annotation if this is intentional}} | ||||
let d3 = ["b" : B(), "c" : C()] | let d3 = ["b" : B(), "c" : C()] | |||
let _: Int = d3 // expected-error{{value of type '[String : A]'}} | let _: Int = d3 // expected-error{{value of type '[String : A]'}} | |||
let _ = ["a" : B(), 17 : "seventeen", 3.14159 : "Pi"] | let _ = ["a" : B(), 17 : "seventeen", 3.14159 : "Pi"] | |||
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[AnyHashable : Any]'}} | // expected-error@-1{{heterogeneous collection literal could only be inferred to '[AnyHashable : Any]'}} | |||
let _ = ["a" : "hello", 17 : "string"] | let _ = ["a" : "hello", 17 : "string"] | |||
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[AnyHashable : String]'}} | // expected-error@-1{{heterogeneous collection literal could only be inferred to '[AnyHashable : String]'}} | |||
} | } | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 2 lines changed or added |