Skip to content

heterogeneous collection literal could only be inferred warning for a homogeneous collection literal #61850

@simanerush

Description

@simanerush

Consider the following code:

class Base { }
class Derived : Base { }

let arr: [Base]

for case _ as [Derived] in [arr] {} // warning: heterogeneous collection literal could only be inferred to '[[Base]]'; add explicit type annotation if this is intentional

This diagnostics should not be emitted.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsfor-in loopsFeature: for-in loopsliteralsFeature → expressions: Literals such as an integer or string literalstatementsFeature: statementstype checkerArea → compiler: Semantic analysistype inferenceFeature: type inference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions