-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsliteralsFeature → expressions: Literals such as an integer or string literalFeature → expressions: Literals such as an integer or string literalswift 5.9type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected warningBug: Unexpected warningBug: Unexpected warning
Description
With this code:
func asJSON(_ a: [String: Any]) { print(a) }
asJSON([
"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
dm-zharov, alexito4, xiemotongye and kwakueshun
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsliteralsFeature → expressions: Literals such as an integer or string literalFeature → expressions: Literals such as an integer or string literalswift 5.9type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected warningBug: Unexpected warningBug: Unexpected warning