IDE:Visual Studio X/Fire Version:10.0.0.2409 (develop) Target (If relevant): Net Description:
Swift allows overloading by external argument label. This is already allowed for functions, but not initializers.
Expected Behavior:
Compiles. Actual Behavior:
“E: Duplicate constructor with same signature “init(other b: Int)” [<file> (<line>)]”
“N: Previous declaration was here [<file> (<line>)]” Steps:
struct S {
init(some a: Int) {} // Note Here
init(other b: Int) {} // Error Here
}
Unfortunately this is a limitation of .NET/Java itself. Since these have to map to real constructors, they don’t allow that. I haven’t found a way to solve this.
struct S {
init(some a: Int) { /* code a */ }
init(other b: Int) { /* code b */}
init(_ c: Int) { /* code c */ }
}
To something more like this:
struct S {
enum __S_RemObjLabels {
case some
case other
}
init(_ x: Int, _ l: __RemObjsLabels) {
switch l {
case .some:
/* code a */
case .other:
/* code b */
}
}
init(_ c: Int) { /* code c */ }
}
Would that work?
However, until labeled inits are supported, I request the errors changed to be:
struct S {
init(some a: Int) {} // E: Labeled (initializers|constructors) unsupported on `.NET`
init(other b: Int) {} // E: Labeled (initializers|constructors) unsupported on `.NET`
}
As they are not redeclarations, they are simply both declaring something unsupported on the .NET platform.