Skip to content
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-6285] More incorrect diagnostics with generics #48835

Closed
NachoSoto opened this issue Nov 2, 2017 · 2 comments
Closed

[SR-6285] More incorrect diagnostics with generics #48835

NachoSoto opened this issue Nov 2, 2017 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-6285
Radar None
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 4.0.2 (swiftlang-900.0.69.1 clang-900.0.38)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @NachoSoto
Priority Medium

md5: 570e6454e0afc0ed5445de853c1ce030

Issue Description:

extension String {
    static func f<C: Collection>(_ c: C, limit: Int? = nil) where C.Element == String, C.IndexDistance == Int { }
}

let l = AnyCollection(
    ["a"].lazy.map { $0 }
)

let x = String.f(l, limit: 2)

Produces:

error: repl.swift:9:16: error: type 'Int?' does not conform to protocol 'ExpressibleByIntegerLiteral'
let x = String.f(l, limit: 2)
               ^

If I move the 2 outside, I get another useless, though probably closer to the truth, diagnostic:

extension String {
    static func f<C: Collection>(_ c: C, limit: Int? = nil) where C.Element == String, C.IndexDistance == Int { }
}

let l = AnyCollection(
    ["a"].lazy.map { $0 }
)

let limit = 2
let x = String.f(l, limit: limit)
error: repl.swift:10:16: error: generic parameter 'C' could not be inferred
let x = String.f(l, limit: limit)
               ^

I still have no idea why `AnyCollection<String>` is not compatible here. Looks like the type defines `IndexDistance` as `IntMax`, which I can't get docs on what that type is.
Regardless, if that's what the error is, I'd expect something like `f requires C.IndexDistance to be Int, AnyCollection<String>.IndexDistance is IntMax`.

@belkadan
Copy link
Contributor

belkadan commented Nov 2, 2017

cc @xedin

@xedin
Copy link
Member

xedin commented Feb 6, 2020

I have tried both examples with 11.4b1 and both type-check correctly now. It might have been a bug in generic signature builder which has since been fixed. @NachoSoto Could you please verify?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants