swiftlang/swift

Missing fix-it when opaque property type is inferred

Open

#69.241 aberto em 18 de out. de 2023

Ver no GitHub
 (6 comments) (0 reactions) (1 assignee)Swift (10.719 forks)batch import
compilerdiagnostics qualityfix-itsgood first issueimprovementopaque result typesopaque typesswift 6.0type checker

Métricas do repositório

Stars
 (69.989 stars)
Métricas de merge de PR
 (Mesclagem média 8d 17h) (510 fundiu PRs em 30d)

Description

Description When the type of a variable or property is inferred as an opaque type, the compiler emits an error to that effect:

Property definition has inferred type 'some Proto', involving the 'some' return type of another declaration

Steps to reproduce When compiling this code, the last line has the above error attached.:

protocol Proto {}
struct Concrete: Proto {}
func getProto() -> some Proto { Concrete() }

let value = getProto() // error

Expected behavior Since the fix is straightforward and included in the error message, the compiler should offer a fixit that would rectify the problem:

let value: some Proto = getProto()

Environment

  • Swift compiler version info Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) Target: arm64-apple-macosx14.0

Guia do colaborador