"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/Constraints/array_literal.swift" between
swift-swift-5.8-RELEASE.tar.gz and swift-swift-5.8.1-RELEASE.tar.gz

About: Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns (developed by Apple).

array_literal.swift  (swift-swift-5.8-RELEASE):array_literal.swift  (swift-swift-5.8.1-RELEASE)
skipping to change at line 128 skipping to change at line 128
class A { } class A { }
class B : A { } class B : A { }
class C : A { } class C : A { }
/// Check for defaulting the element type to 'Any' / 'Any?'. /// Check for defaulting the element type to 'Any' / 'Any?'.
func defaultToAny(i: Int, s: String) { func defaultToAny(i: Int, s: String) {
let a1 = [1, "a", 3.5] let a1 = [1, "a", 3.5]
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any]'; add explicit type annotation if this is intentional}} // expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any]'; add explicit type annotation if this is intentional}}
let _: Int = a1 // expected-error{{value of type '[Any]'}} let _: Int = a1 // expected-error{{value of type '[Any]'}}
let _ = ([1, "a"])
// expected-error@-1{{heterogeneous collection literal could only be inferred
to '[Any]'; add explicit type annotation if this is intentional}}
let _ = [1, true, []]
// expected-error@-1:11 {{heterogeneous collection literal could only be infer
red to '[Any]'; add explicit type annotation if this is intentional}}
let a2: Array = [1, "a", 3.5] let a2: Array = [1, "a", 3.5]
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any]'; add explicit type annotation if this is intentional}} // expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any]'; add explicit type annotation if this is intentional}}
let _: Int = a2 // expected-error{{value of type '[Any]'}} let _: Int = a2 // expected-error{{value of type '[Any]'}}
let a3 = [1, "a", nil, 3.5] let a3 = [1, "a", nil, 3.5]
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any?]'; add explicit type annotation if this is intentional}} // expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any?]'; add explicit type annotation if this is intentional}}
let _: Int = a3 // expected-error{{value of type '[Any?]'}} let _: Int = a3 // expected-error{{value of type '[Any?]'}}
let a4: Array = [1, "a", nil, 3.5] let a4: Array = [1, "a", nil, 3.5]
// expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any?]'; add explicit type annotation if this is intentional}} // expected-error@-1{{heterogeneous collection literal could only be inferred to '[Any?]'; add explicit type annotation if this is intentional}}
let _: Int = a4 // expected-error{{value of type '[Any?]'}} let _: Int = a4 // expected-error{{value of type '[Any?]'}}
let a5 = [] let a5 = []
// expected-error@-1{{empty collection literal requires an explicit type}} // expected-error@-1{{empty collection literal requires an explicit type}}
let _: Int = a5 // expected-error{{value of type '[Any]'}} let _: Int = a5 // expected-error{{value of type '[Any]'}}
let _: [Any] = [] let _: [Any] = []
let _: [Any] = [1, "a", 3.5] let _: [Any] = [1, "a", 3.5]
let _: [Any] = [1, "a", [3.5, 3.7, 3.9]] let _: [Any] = [1, "a", [3.5, 3.7, 3.9]]
let _: [Any] = [1, "a", [3.5, "b", 3]] let _: [Any] = [1, "a", [3.5, "b", 3]]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any]'; add explicit type annotation if this is intentional}}
let _: [Any] = [1, [2, [3]]] let _: [Any] = [1, [2, [3]]]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any]'; add explicit type annotation if this is intentional}}
func f1() -> [Any] { func f1() -> [Any] {
[] []
} }
let _: [Any?] = [1, "a", nil, 3.5] let _: [Any?] = [1, "a", nil, 3.5]
let _: [Any?] = [1, "a", nil, [3.5, 3.7, 3.9]] let _: [Any?] = [1, "a", nil, [3.5, 3.7, 3.9]]
let _: [Any?] = [1, "a", nil, [3.5, "b", nil]] let _: [Any?] = [1, "a", nil, [3.5, "b", nil]]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any?]'; add explicit type annotation if this is intentional}}
let _: [Any?] = [1, [2, [3]]] let _: [Any?] = [1, [2, [3]]]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any]'; add explicit type annotation if this is intentional}}
let _: [Any?] = [1, nil, [2, nil, [3]]] let _: [Any?] = [1, nil, [2, nil, [3]]]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any?]'; add explicit type annotation if this is intentional}}
let a6 = [B(), C()] let a6 = [B(), C()]
let _: Int = a6 // expected-error{{value of type '[A]'}} let _: Int = a6 // expected-error{{value of type '[A]'}}
let a7: some Collection = [1, "Swift"] let a7: some Collection = [1, "Swift"]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any]'; add explicit type annotation if this is intentional}} {{41-41= as [Any]}}
let _: (any Sequence)? = [1, "Swift"] let _: (any Sequence)? = [1, "Swift"]
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any]'; add explicit type annotation if this is intentional}}
let _: any Sequence = [1, nil, "Swift"] let _: any Sequence = [1, nil, "Swift"]
// expected-warning@-1{{heterogeneous collection literal could only be inferre
d to '[Any?]'; add explicit type annotation if this is intentional}}
let _ = [1, true, ([], 1)]
// expected-error@-1 {{heterogeneous collection literal could only be inferred
to '[Any]'; add explicit type annotation if this is intentional}}
// expected-warning@-2 {{empty collection literal requires an explicit type}}
let _ = true ? [] : [] let _ = true ? [] : []
// expected-warning@-1{{empty collection literal requires an explicit type}}
let _ = (true, ([1, "Swift"])) let _ = (true, ([1, "Swift"]))
//expected-warning@-1{{heterogeneous collection literal could only be inferred
to '[Any]'; add explicit type annotation if this is intentional}}
let _ = ([1, true])
//expected-error@-1{{heterogeneous collection literal could only be inferred t
o '[Any]'; add explicit type annotation if this is intentional}}
func f2<T>(_: [T]) {} func f2<T>(_: [T]) {}
func f3<T>() -> [T]? {} func f3<T>() -> [T]? {}
f2([]) f2([])
// expected-warning@-1{{empty collection literal requires an explicit type}}
f2([1, nil, ""]) f2([1, nil, ""])
// expected-warning@-1{{heterogeneous collection literal could only be inferre d to '[Any?]'; add explicit type annotation if this is intentional}}
_ = f3() ?? [] _ = f3() ?? []
// expected-warning@-1{{empty collection literal requires an explicit type}}
} }
func noInferAny(iob: inout B, ioc: inout C) { func noInferAny(iob: inout B, ioc: inout C) {
var b = B() var b = B()
var c = C() var c = C()
let _ = [b, c, iob, ioc] // do not infer [Any] when elements are lvalues or in out let _ = [b, c, iob, ioc] // do not infer [Any] when elements are lvalues or in out
let _: [A] = [b, c, iob, ioc] // do not infer [Any] when elements are lvalues or inout let _: [A] = [b, c, iob, ioc] // do not infer [Any] when elements are lvalues or inout
b = B() b = B()
c = C() c = C()
} }
 End of changes. 14 change blocks. 
22 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)