DaveS
8 September 2023 16:13
1
Normally warning in Xcode are pretty spot on, but this one started appearing after the last update
the warning says to insert “as [AnyObject]”… but if you look at the code line it is already there, and [FIX] simple inserts another one, and the warning remains.
Note : the code compiles and runs correctly, it is just annoying
DaveS
10 September 2023 15:39
5
No idea how that github is related to this topic
If you walk back the series of commits etc you get to
opened 01:12AM - 12 Jul 22 UTC
closed 08:09PM - 16 Aug 22 UTC
bug
compiler
good first issue
diagnostics QoI
type checker
type inference
literals
swift 5.8
When a heterogeneous array literal could only be inferred to have type `[Any]`, … the compiler humbly states that this may not match our expectation:
```swift
let array = [1, "Swift"] // error: heterogeneous collection literal could only be inferred to '[Any]'; add explicit type annotation if this is intentional
```
However, this never seems to happen in the presence of a contextual type:
```swift
let array: any Sequence = [1, "Swift"] // OK?
```
**Expected behavior**
The compiler should not assume that a contextual type other than `[Any]` or, perhaps, `[Any?]` makes the inferred element type any more intentional. In this case, the error should be downgraded to a warning for source compatibility.
**Environment**
Swift version 5.8-dev (LLVM 116acf4edcf4f06, Swift d565ba5084a169d)
When a heterogeneous array literal could only be inferred to have type [Any]
, the compiler humbly states that this may not match our expectation:
which sort of sounds like the issue you were seeing
there’s a fix checked in
then a revert of that
all this IS in Apples Swift github
1 Like
DaveS
10 September 2023 20:53
7
Ok… does that mean that it IS a bug in Swift, but they fixed it, then decided to unfix it?
I guess if you know how GIT works, you could figure it out, but I don’t nor do I care to (learn GIT that is)
Didn’t really eat then entire commit history
Didnt really read the entire commit history
But it seems to me that maybe this warning/error got added and shouldnt have and so that has been reverted for a newer build
But I COULD easily be misreading that
EDITed because WOW talk about typo !
1 Like
Rick.A
25 September 2023 10:00
10
Thorsten said “Probably a bug”
And I pointed where the correlated Swift bugs were located.
And this is the current state of affairs:
opened 12:08AM - 01 Mar 23 UTC
closed 10:26PM - 20 Apr 23 UTC
bug
compiler
diagnostics QoI
type checker
type inference
literals
expressions
swift 5.9
unexpected warning
With this code:
```swift
func asJSON(_ a: [String: Any]) { print(a) }
asJ… SON([
"a": [
"b": "c",
"d": [
"e": "f",
],
],
])
```
Swift 5.8 from Xcode 14.3 beta 2 warns that the collection is inferred as Any:
```
foo.swift:4:10: warning: heterogeneous collection literal could only be inferred to '[String : Any]'; add explicit type annotation if this is intentional
"a": [
^
```
In this case I'm surprised to see this warning since the function it's being passed to explicitly takes `[String: Any]`, so it being inferred as Any seems expected and I don't think needs a warning
XCode 15 contains Swift 5.9 , are you still affected by a problem with it?
1 Like