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-4466] Extra arguments error for valid call to max #47043

Closed
swift-ci opened this issue Apr 2, 2017 · 3 comments
Closed

[SR-4466] Extra arguments error for valid call to max #47043

swift-ci opened this issue Apr 2, 2017 · 3 comments
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

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 2, 2017

Previous ID SR-4466
Radar None
Original Reporter drumnkyle (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 8.2.1

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

md5: 46cf44f1674013a639ea99778a24e799

Issue Description:

I get an extra arguments error for a valid call to max. I have tried isolating the code to a playground and it works fine. So, it has something to do with this whole struct, I guess.

The code I'm trying to add is the following:

public struct Measure: ImmutableMeasure, Equatable, RandomAccessCollection {

    /// One slice of `NoteCollection` from a note set at a particular time
    public struct NoteSlice: Equatable {
        public let noteSetIndex: Int
        public let noteCollection: NoteCollection
        public static func ==(lhs: NoteSlice, rhs: NoteSlice) -> Bool {
            return lhs.noteSetIndex == rhs.noteSetIndex &&
            lhs.noteCollection == rhs.noteCollection
        }
    }

    // MARK: - Collection Conformance

    public struct MeasureIterator: IteratorProtocol {
        var currentIndex: Int = 0
        let notes: [[NoteCollection]]

        init(_ measure: Measure) {
            notes = measure.notes
        }

        public mutating func next() -> [NoteSlice]? {
            defer { currentIndex += 1 }
            return Measure.noteSlices(at: currentIndex, in: notes)
        }
    }
    private static func noteSlices(at position: Int, in notes: [[NoteCollection]]) -> [NoteSlice]? {
        return notes.enumerated().flatMap { noteSetIndex, noteCollections in
            guard let noteCollection = noteCollections[safe: position] else {
                return nil
            }
            return NoteSlice(noteSetIndex: noteSetIndex, noteCollection: noteCollection)
        }
    }
    public typealias Index = Int
    public var startIndex: Int {
        return 0
    }
    public var endIndex: Int {
        return notes.reduce(0) { (prev, noteCollections) in
//            return max(prev, noteCollections.endIndex)
            return prev > noteCollectionIndexes.endIndex ? prev : noteCollectionIndexes.endIndex
        }
    }
    public subscript(position: Index) -> Iterator.Element {
        return Measure.noteSlices(at: position, in: notes)!
    }
    public func index(after i: Int) -> Int {
        return notes.index(after: i)
    }
    public func index(before i: Int) -> Int {
        return notes.index(before: i)
    }
    public typealias Iterator = MeasureIterator
    public func makeIterator() -> Iterator {
        return MeasureIterator(self)
    }

    // MARK: - Main Properties

    public let timeSignature: TimeSignature

This is a link to the file I'm trying to modify at the top of the struct: https://github.com/drumnkyle/music-notation-core/blob/master/Sources/Measure.swift

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2017

Collection has its own max method, which you are accidentally referring to. You can use Swift.max to get the top-level function.

I'll leave this open until I can find a dup for improving the diagnostics.

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 3, 2017

This appears to have improved dramatically with Swift 3.1:

protocol P {
    func max()
}
extension P {
    func max() {}
}
struct Foo: P {
    func bar() {
        max(1, 2);
    }
}

ERROR at line 9, col 3: use of 'max' refers to instance method 'max()' rather than global function 'max' in module 'Swift'
                max(1, 2);
                ^
NOTE at line 9, col 3: use 'Swift.' to reference the global function in module 'Swift'
                max(1, 2);
                ^
                Swift.
Swift.max:7:13: note: 'max' declared here
public func max<T>(_ x: T, _ y: T) -> T where T : Comparable

@belkadan
Copy link
Contributor

belkadan commented Apr 4, 2017

Ah, that's probably all we would do. Marking as fixed in Swift 3.1.

@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
Projects
None yet
Development

No branches or pull requests

2 participants