Files
swift-mirror/test/Constraints/rdar47787705.swift
Pavel Yaskevich 1d8cee9cb4 [ConstraintSystem] Detect invalid initializer references early
Currently invalid initializer references are detected and
diagnosed in solution application phase, but that's too
late because solver wouldn't have required information while
attempting to determine the best solution, which might result
in viable solutions being ignored in favour of incorrect ones e.g.

```swift
protocol P {
  init(value: Int)
}

class C {
  init(value: Int, _: String = "") {}
}

func make<T: P & C>(type: T.Type) -> T {
  return T.init(value: 0)
}
```

In this example `init` on `C` would be preferred since it
comes from the concrete type, but reference itself is invalid
because it's an attempt to construct class object using
metatype value via non-required initalizer.

Situations like these should be recognized early and invalid
use like in case of `C.init` should be ranked lower or diagnosed
if that is the only possible solution.

Resolves: rdar://problem/47787705
2019-02-05 10:25:36 -08:00

15 lines
286 B
Swift

// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
protocol P {
init(value: Int)
}
class C {
init(value: Int, otherValue: String = "") {}
}
func make<T: P & C>(type: T.Type) -> T {
// CHECK: [[INIT:.*]] = witness_method $T, #P.init
return T.init(value: 0)
}