Element vs. Iterator.Element

Hi,

This extension on Array works as expected:

extension Array where Element: CustomStringConvertible {
    func f(_ x: Element) -> String {
        return x.description
    }
}

But when I use Iterator.Element instead, I get an error message (error: value of type 'Element' has no member 'description'):

extension Array where Iterator.Element: CustomStringConvertible {
    func f(_ x: Iterator.Element) -> String {
        return x.description
    }
}

I assume this is a type checker bug, but before I report it, I wanted to make sure that that’s really the case. Or is there a difference between Element and
Iterator.Element?

Thanks and best regards,
Toni

There shouldn't be. It's a bug, IMO.

···

on Mon Oct 31 2016, Toni Suter <swift-users-AT-swift.org> wrote:

Hi,

This extension on Array works as expected:

extension Array where Element: CustomStringConvertible {
    func f(_ x: Element) -> String {
        return x.description
    }
}

But when I use Iterator.Element instead, I get an error message (error: value of type 'Element' has
no member 'description'):

extension Array where Iterator.Element: CustomStringConvertible {
    func f(_ x: Iterator.Element) -> String {
        return x.description
    }
}

I assume this is a type checker bug, but before I report it, I wanted to make sure that that’s
really the case. Or is there a difference between Element and
Iterator.Element?

--
-Dave

Ok, I have filed a bug: [SR-3102] Protocol conformance constraint doesn't work under certain circumstances · Issue #45690 · apple/swift · GitHub

Best regards,
Toni

···

Am 31.10.2016 um 19:32 schrieb Dave Abrahams via swift-users <swift-users@swift.org>:

on Mon Oct 31 2016, Toni Suter <swift-users-AT-swift.org <http://swift-users-at-swift.org/&gt;&gt; wrote:

Hi,

This extension on Array works as expected:

extension Array where Element: CustomStringConvertible {
   func f(_ x: Element) -> String {
       return x.description
   }
}

But when I use Iterator.Element instead, I get an error message (error: value of type 'Element' has
no member 'description'):

extension Array where Iterator.Element: CustomStringConvertible {
   func f(_ x: Iterator.Element) -> String {
       return x.description
   }
}

I assume this is a type checker bug, but before I report it, I wanted to make sure that that’s
really the case. Or is there a difference between Element and
Iterator.Element?

There shouldn't be. It's a bug, IMO.

--
-Dave

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

I don’t remember the details, but IIRC ‘Iterator’ is an inferred associated type on Array, so it cannot appear in the ‘where’ clause of an extension. This is a known limitation of the name lookup code — presently it cannot recur into associated type inference due to circularity. We plan on addressing this with the ‘iterative declaration checker’, but that is some ways off.

Slava

···

On Oct 31, 2016, at 5:28 AM, Toni Suter via swift-users <swift-users@swift.org> wrote:

Hi,

This extension on Array works as expected:

extension Array where Element: CustomStringConvertible {
    func f(_ x: Element) -> String {
        return x.description
    }
}

But when I use Iterator.Element instead, I get an error message (error: value of type 'Element' has no member 'description'):

extension Array where Iterator.Element: CustomStringConvertible {
    func f(_ x: Iterator.Element) -> String {
        return x.description
    }
}

I assume this is a type checker bug, but before I report it, I wanted to make sure that that’s really the case. Or is there a difference between Element and
Iterator.Element?

Thanks and best regards,
Toni
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users