Skip to content

[SR-1876] Overloaded generic methods missing default parameters don't select most specific function #44485

Open
@swift-ci

Description

@swift-ci
Previous ID SR-1876
Radar rdar://problem/27033947
Original Reporter sswezeystk (JIRA User)
Type Bug
Environment

Xcode 8 Beta 1

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, 3.0Regression, TypeChecker
Assignee @slavapestov
Priority Medium

md5: 36965762b7cc9100f831c2eb26c79e70

Issue Description:

When there are several functions with similar signatures, but differing generic constraints, omitting default parameters in the function call results in the wrong function being called. This works correctly with Swift 2.2 in Xcode 7.3

import Foundation

protocol A {
    init(int: Int)
}

extension Int: A {
    init(int: Int) {
        self.init(int)
    }
}
extension String: A {
    init(int: Int) {
        self.init(int.description)
    }
}

protocol B {
    init(string: String)
}

extension String: B {
    init(string: String) {
        self.init(string)
    }
}

func d<T where T: A, T: B>(key key: String, new: Bool = true) -> Array<T> {
    return [T(int:1), T(string:"b")]
}

func d<T where T: A>(key key: String, new: Bool = true) -> Array<T> {
    return [T(int: 3), T(int: 4)]
}

func d<T>(key key: String) -> Array<T> {
    return Array<T>()
}

let a: Array<Int> = d(key: "adf")
let aa: Array<Int> = d(key: "adf", new: false)
let b: Array<String> = d(key: "adfa")
let bb: Array<String> = d(key: "adfa", new: false)
let c: Array<Double> = d(key: "dfa")

print(a, aa, a == aa) // should be true
print(b, bb, b == bb) // should be true
print(c)

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfregressionswift 3.0type checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions