Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'


(Adriano Ferreira) #1

Hi everyone!

I’m converting some code to Swift 3 and got this issue?

Does anybody know what’s going on?

Here’s the code, before and after conversion:

// Swift 2.2
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, @noescape closure: () -> Void) {

        for _ in self.stride(to: upper, by: step) {
            closure()
        }
    }
}

// Swift 3
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, _ closure: @noescape () -> Void) {

        for _ in stride(from: self, to: upper, by: step) {
            closure()
        }
    }
}

// Usage
1.up(to: 10, by: 2) {
    print("Hi!")
}

Best,

— A


(Joe Groff) #2

This is a known bug. The definition of 'stride' inside 'Int' for migration from Swift 2 causes the compiler to fail to find the global function. https://bugs.swift.org/browse/SR-1798

-Joe

···

On Jul 4, 2016, at 8:41 PM, Adriano Ferreira via swift-users <swift-users@swift.org> wrote:

Hi everyone!

I’m converting some code to Swift 3 and got this issue?

<Screen Shot 2016-07-04 at 11.30.45 PM.png>

Does anybody know what’s going on?

Here’s the code, before and after conversion:

// Swift 2.2
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, @noescape closure: () -> Void) {

        for _ in self.stride(to: upper, by: step) {
            closure()
        }
    }
}

// Swift 3
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, _ closure: @noescape () -> Void) {

        for _ in stride(from: self, to: upper, by: step) {
            closure()
        }
    }
}

// Usage
1.up(to: 10, by: 2) {
    print("Hi!")
}

Best,

— A
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Zhao Xin) #3

In Swift 3,

func stride<T : Strideable <apple-reference-documentation://hsYF4ATMnE>>(
from start: T, to end: T, by stride: T.Stride) -> StrideTo
<apple-reference-documentation://hs9b7RwjpY><T>

Int does not conform to Strideable.

Adopted By

CGFloat
Decimal
Double
Float
Float80
String.UTF16View.Index
UnsafeMutablePointer
UnsafePointer

​In Swift 2.2,

@warn_unused_result func stride(to *end*: Self, by *stride*: Self.Stride)
-> StrideTo
<file:///Users/zhaoxin/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.OSX.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StrideTo_Structure/index.html#//apple_ref/swift/struct/s:Vs8StrideTo>
<Self>

It uses Self, which means the type of the variable, instead of T.

Zhaoxin

···

On Tue, Jul 5, 2016 at 11:41 AM, Adriano Ferreira via swift-users < swift-users@swift.org> wrote:

Hi everyone!

I’m converting some code to Swift 3 and got this issue?

Does anybody know what’s going on?

Here’s the code, before and after conversion:

// Swift 2.2
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, @noescape closure: () -> Void)
{

        for _ in self.stride(to: upper, by: step) {
            closure()
        }
    }
}

// Swift 3
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, _ closure: @noescape () ->
Void) {

        for _ in stride(from: self, to: upper, by: step) {
            closure()
        }
    }
}

// Usage
1.up(to: 10, by: 2) {
    print("Hi!")
}

Best,

— A

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


(Shawn Erickson) #4

Int conforms to Strideable byway of Integer <- SignedInteger <- Int (not
exactly sure how it will be once the integer proposal is implemented but it
will still be strideable).

-Shawn

···

On Mon, Jul 4, 2016 at 10:38 PM Zhao Xin via swift-users < swift-users@swift.org> wrote:

In Swift 3,

func stride<T : Strideable>(from start: T, to end: T, by stride:
T.Stride) -> StrideTo<T>

Int does not conform to Strideable.

Adopted By

CGFloat
Decimal
Double
Float
Float80
String.UTF16View.Index
UnsafeMutablePointer
UnsafePointer

​In Swift 2.2,

@warn_unused_result func stride(to *end*: Self, by *stride*: Self.Stride)
-> StrideTo<Self>

It uses Self, which means the type of the variable, instead of T.

Zhaoxin

On Tue, Jul 5, 2016 at 11:41 AM, Adriano Ferreira via swift-users < > swift-users@swift.org> wrote:

Hi everyone!

I’m converting some code to Swift 3 and got this issue?

Does anybody know what’s going on?

Here’s the code, before and after conversion:

// Swift 2.2
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, @noescape closure: () ->
Void) {

        for _ in self.stride(to: upper, by: step) {
            closure()
        }
    }
}

// Swift 3
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, _ closure: @noescape () ->
Void) {

        for _ in stride(from: self, to: upper, by: step) {
            closure()
        }
    }
}

// Usage
1.up(to: 10, by: 2) {
    print("Hi!")
}

Best,

— A

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

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


(Zhao Xin) #5

You are right. Int conforms to Strideable.

Now it seams like a bug. As in a playground. below are code works and
doesn't work

extension Int {

    func test() {

        let temp = stride(from:1, to:10, by:2) // error

    }

}

extension Float {

    func test() {

        let temp = stride(from:1, to:10, by:2) // error

    }

}

extension String {

    func test() {

        let temp = stride(from:1, to:10, by:2) // works

    }

}

class A {

}

extension A {

    func test() {

        let temp = stride(from:1, to:10, by:2) // works

    }

}

struct B {

}

extension B {

    func test() {

        let temp = stride(from:1, to:10, by:2) // works

    }

}

func test() {

    let temp = stride(from:1, to:10, by:2) //works

}

let temp = stride(from:1, to:10, by:2) // works

​It is nothing bug a bug?​

​Zhaoxin​

···

On Tue, Jul 5, 2016 at 10:16 PM, Shawn Erickson <shawnce@gmail.com> wrote:

Int conforms to Strideable byway of Integer <- SignedInteger <- Int (not
exactly sure how it will be once the integer proposal is implemented but it
will still be strideable).

-Shawn

On Mon, Jul 4, 2016 at 10:38 PM Zhao Xin via swift-users < > swift-users@swift.org> wrote:

In Swift 3,

func stride<T : Strideable>(from start: T, to end: T, by stride:
T.Stride) -> StrideTo<T>

Int does not conform to Strideable.

Adopted By

CGFloat
Decimal
Double
Float
Float80
String.UTF16View.Index
UnsafeMutablePointer
UnsafePointer

​In Swift 2.2,

@warn_unused_result func stride(to *end*: Self, by *stride*: Self.Stride)
-> StrideTo<Self>

It uses Self, which means the type of the variable, instead of T.

Zhaoxin

On Tue, Jul 5, 2016 at 11:41 AM, Adriano Ferreira via swift-users < >> swift-users@swift.org> wrote:

Hi everyone!

I’m converting some code to Swift 3 and got this issue?

Does anybody know what’s going on?

Here’s the code, before and after conversion:

// Swift 2.2
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, @noescape closure: () ->
Void) {

        for _ in self.stride(to: upper, by: step) {
            closure()
        }
    }
}

// Swift 3
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, _ closure: @noescape () ->
Void) {

        for _ in stride(from: self, to: upper, by: step) {
            closure()
        }
    }
}

// Usage
1.up(to: 10, by: 2) {
    print("Hi!")
}

Best,

— A

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

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


(Adriano Ferreira) #6

Any suggestions on how to work around it or to fix it?

Thanks in advance!

— A

···

On Jul 5, 2016, at 12:00 PM, Zhao Xin <owenzx@gmail.com> wrote:

You are right. Int conforms to Strideable.

Now it seams like a bug. As in a playground. below are code works and doesn't work

extension Int {
    func test() {
        let temp = stride(from:1, to:10, by:2) // error
    }
}

extension Float {
    func test() {
        let temp = stride(from:1, to:10, by:2) // error
    }
}

extension String {
    func test() {
        let temp = stride(from:1, to:10, by:2) // works
    }
}

class A {
    
}

extension A {
    func test() {
        let temp = stride(from:1, to:10, by:2) // works
    }
}

struct B {
    
}

extension B {
    func test() {
        let temp = stride(from:1, to:10, by:2) // works
    }
}

func test() {
    let temp = stride(from:1, to:10, by:2) //works
}

let temp = stride(from:1, to:10, by:2) // works

​It is nothing bug a bug?​

​Zhaoxin​

On Tue, Jul 5, 2016 at 10:16 PM, Shawn Erickson <shawnce@gmail.com <mailto:shawnce@gmail.com>> wrote:
Int conforms to Strideable byway of Integer <- SignedInteger <- Int (not exactly sure how it will be once the integer proposal is implemented but it will still be strideable).

-Shawn

On Mon, Jul 4, 2016 at 10:38 PM Zhao Xin via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
In Swift 3,

func stride<T : Strideable <>>(from start: T, to end: T, by stride: T.Stride) -> StrideTo <><T>

Int does not conform to Strideable.

Adopted By

CGFloat
Decimal
Double
Float
Float80
String.UTF16View.Index
UnsafeMutablePointer
UnsafePointer

​In Swift 2.2,

@warn_unused_result func stride(to end: Self, by stride: Self.Stride) -> StrideTo <><Self>

It uses Self, which means the type of the variable, instead of T.

Zhaoxin

On Tue, Jul 5, 2016 at 11:41 AM, Adriano Ferreira via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
Hi everyone!

I’m converting some code to Swift 3 and got this issue?

Does anybody know what’s going on?

Here’s the code, before and after conversion:

// Swift 2.2
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, @noescape closure: () -> Void) {

        for _ in self.stride(to: upper, by: step) {
            closure()
        }
    }
}

// Swift 3
extension Int {

    // Repeat a block of code from `self` up to a limit
    func up(to upper: Int, by step: Int = 1, _ closure: @noescape () -> Void) {

        for _ in stride(from: self, to: upper, by: step) {
            closure()
        }
    }
}

// Usage
1.up(to: 10, by: 2) {
    print("Hi!")
}

Best,

— A

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

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