Skip to content

[SR-5020] Poor diagnostic using static property on generic struct when missing explicit type #47596

@milseman

Description

@milseman
mannequin
Previous ID SR-5020
Radar None
Original Reporter @milseman
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: cbeac3c4000ef8cf021562391607daed

Issue Description:

Trying to compile something like:

struct S<T> { static var desc: String { return "hello" } }
print(S.desc)

Gives the not-so-helpful error message:

error: repl.swift:2:9: error: argument type 'String' does not conform to expected type 'Any'
print(S.desc)
      ~~^~~~
             as Any

The solution is to explicitly provide the type:

print(S<Any>.desc) 

It would be nice to get a more targeted error message here, and maybe even a fixit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationtype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions