New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-2921] Some implicitly coerced from <x> to Any warnings missing a source location #45515
Comments
Comment by Ben A (JIRA) Call sites that I can pick out easily that might trigger this seem to be:
But as I said, I've tried explicitly unwrapping values in these cases to no avail. |
@rudkx, CodaFi (JIRA User), can you think of where this would happen? |
I saw a report of this yesterday, and in that case the issue was a dictionary [ String : UIColor? ] that was being passed to a function expecting [ String : Any ]. I'm not sure why the source location is wrong in that case. |
Comment by Ben A (JIRA) If any headway is made here, I'm happy to try out a snapshot or build a toolchain locally to try it out in Xcode to verify the fix. And of course I'll update here if I can come up with an isolated repro case. |
I just figured out what the issue is (at least with the test case I mentioned) and will submit a patch soon. |
Merged: 623a163 |
The source locations should now appear. Please re-open, or open a new ticket, if you find that it's not happening once you pick up a build that has the fix. |
Comment by Ben A (JIRA) @rudkx thanks! |
Comment by Ben A (JIRA) Tested with swift-DEVELOPMENT-SNAPSHOT-2016-10-13-a, and this is fixed now. Thanks! |
Not fixed for me using swift-DEVELOPMENT-SNAPSHOT-2016-11-01 (a) |
@dmcgloin Do you have a test case that demonstrates the issue you're seeing? |
I will try to extract a simple example as soon as possible |
Comment by Mitchell Clay (JIRA) Noticed this error in XCode 8.1 release, sample code: func nullToNil(value : Any?) -> Any? {
if value is NSNull {
return nil
}
return value
}
func parse(json: [String: Any]) {
let childObject = json["child"] as! [String: Any?]
let desc = nullToNil(childObject["description"]) as? String
} I will get "Expression implicitly coerced from Any? to Any" on the "let desc" line EDIT: I have realized that this may not be a bug with current version more that it was a bug with previous version that is now fixed. The correct code is: func nullToNil(value : Any?) -> Any? {
if value is NSNull {
return nil
}
return value
}
func parse(json: [String: Any]) {
let childObject = json["child"] as! [String: *Any*]
let desc = nullToNil(childObject["description"]) as? String
} Because childObject["description"] is automatically considering the fact that the key may be wrong so a nil value could be returned, but for parsing JSON it will be a value or NSNull. |
Here's a snippet that produces a warning without source location. This occurs with Xcode 8 version 8.1 (8B62) with default Swift 3. Please disregard the two warnings about using let instead of var. func doTest()
{
var color: String? = "Blue"
var flavor: String? = "Vanilla"
let additionalProperties = ["Color": color, "Flavor": flavor]
self.logEvent("Something happened", additionalProperties: additionalProperties)
}
func logEvent(_ eventName: String, additionalProperties: [String: Any]? = nil)
{
} |
Comment by Tal (JIRA) does this appear to be caused by this bug. See attachment. let message = messageFactory.message(meetHereType: meetHereType, image: image, conversation: conversation, meetLocation: meetLocation, senderLocation: senderLocation, receiverLocation: receiverLocation) |
Comment by Benjamin Encz (JIRA) Still happening for me in Xcode 8.1 (8B62). One example: let string = NSMutableAttributedString(string: text)
let linkAttributes = [NSForegroundColorAttributeName: UIColor.plangridBlue()]
string.setAttributes(linkAttributes, range: buttonRange)} Happens in 5 different locations in our codebase. |
+1, on Xcode Version 8.2 (8C30a) Very similar to @dmcgloin's issue–I'm seeing this happen with |
Can someone who is hitting this try with a recent snapshot? It appears to be fixed on master, e.g. for @dmcgloin's example I get: 7:63: warning: expression implicitly coerced from 'String?' to Any
self.logEvent("Something happened", additionalProperties: additionalProperties) |
I'm still getting this with the 3.0.2 PREVIEW 1 toolchain. Is there anything newer than this that I should try? |
Yes, the December 9 snapshot here: https://swift.org/download/#snapshots |
[EDIT]: Cleaned the project and tried again, and it's reporting the correct location now. |
Comment by Danut Pralea (JIRA) I keep having the warning, along with no location information 🙁 |
It's fixed in Swift 3.1 (Xcode 8.3). Any 3.0.x releases still have the bug. |
Attachment: Download
Environment
macOS Sierra
Swift 3.0.1
Xcode 8.1b3
Additional Detail from JIRA
md5: 83cc0bca9622db0226c0caa1153a1c2b
relates to:
Issue Description:
The result from compiling a few different files in our project is warnings emitted in Xcode that look like this:
I've gone through and explicitly unwrapped as many
String!/?
s as I can identify, but I can't seem to get these to go away. I've tried coming up with a small repro case, since I can't attach the files in question, but so far I haven't figured out what triggers this. We have about 13 of them like this.The text was updated successfully, but these errors were encountered: