swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-220] Compiler unable to resolve types properly

Open swift-ci opened this issue 10 years ago • 4 comments

Previous ID SR-220
Radar None
Original Reporter nikita (JIRA User)
Type Bug

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: d26c0323af50329b2f99c14b0d199518

Issue Description:

struct A<B: CollectionType> {
init(c: B) {
c.startIndex.advancedBy(Int(5), limit: c.endIndex)
}
}

declaration above fails with error:
error: cannot invoke 'advancedBy' with an argument list of type '(Int, limit: B.Index)'
c.startIndex.advancedBy(Int(5), limit: c.endIndex)

replacing Int(5) with 5 makes it compile properly. I was not able to reduce this case further yet, but there should be simple example of the case for sure.

swift-ci avatar Dec 14 '15 05:12 swift-ci

Is this really a bug?
Note that the CollectionType's associated type Index doesn't have to be an Int.
So another way to get your example to compile is to add the following where clause (and thereby constraining it to work only with CollectionTypes whose Index is an Int):

struct A<B: CollectionType where B.Index == Int> {
    init(c: B) {
        c.startIndex.advancedBy(Int(5), limit: c.endIndex)
    }
}

jepers avatar Dec 14 '15 17:12 jepers

Specifically, it's not the Index that is or isn't an Int, but the Index's distance type. But the error message ought to say what overload was expected.

belkadan avatar Dec 14 '15 17:12 belkadan

I think this bug has become invalid, and should be closed as either `Invalid` or `Cannot Reproduce`.

Dante-Broggi avatar Jul 18 '18 04:07 Dante-Broggi

The APIs involved have since been reshaped and the reproducer has become stale. The error now says value of type 'B.Index' has no member 'advancedBy'.

AnthonyLatsis avatar Jun 16 '22 21:06 AnthonyLatsis