Skip to content

Commit e8748a0

Browse files
authored
Update type_inference_from_default_exprs.swift
1 parent bde2e9d commit e8748a0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/Constraints/type_inference_from_default_exprs.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,31 @@ do {
269269

270270
func testInferenceFromClosureVarInvalid<T>(x: T = { let x = "" as Int; return x }()) {}
271271
// expected-error@-1 {{cannot convert value of type 'String' to type 'Int' in coercion}}
272+
273+
// https://github.com/swiftlang/swift/issues/72199
274+
enum S72199_1 {
275+
func testInferFromOtherPos<T>(_: T = 42, _: [T]) {}
276+
// expected-error@-1 {{cannot use default expression for inference of 'T' because it is inferrable from parameters #0, #1}}
277+
}
278+
279+
protocol S72199_DurationProtocol {
280+
281+
}
282+
283+
protocol S72199_InstantProtocol {
284+
associatedtype Duration: S72199_DurationProtocol
285+
}
286+
287+
protocol S72199_ClockProtocol {
288+
associatedtype Instant: S72199_InstantProtocol
289+
}
290+
291+
struct S72199_Duration: S72199_DurationProtocol {}
292+
struct S72199_Instant: S72199_InstantProtocol {
293+
typealias Duration = S72199_Duration
294+
}
295+
struct S72199_Clock: S72199_ClockProtocol {
296+
typealias Instant = S72199_Instant
297+
}
298+
299+
func testS72199_2<T: S72199_ClockProtocol>(_: T.Instant, _: T.Instant.Duration, _: T = S72199_Clock()) {} // Ok

0 commit comments

Comments
 (0)