Skip to content

Commit cccd1b4

Browse files
authored
Merge pull request swiftlang#72024 from belkadan/protocol-extension-default-arguments-test-case
Test existing behavior of default arguments in protocol extensions
2 parents 97a8913 + 475b8ec commit cccd1b4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/Interpreter/protocol_extensions.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,25 @@ extension String: Addable {}
374374
ProtocolExtensionTestSuite.test("MarkerProtocolExtensions") {
375375
expectTrue("hello".increment(this: 11) == 111)
376376
}
377+
378+
protocol DefaultArgumentsInExtension {
379+
func foo(a: Int, b: Int) -> (Int, Int)
380+
}
381+
extension DefaultArgumentsInExtension {
382+
func foo(a: Int, b: Int = 1) -> (Int, Int) {
383+
self.foo(a: a * 10, b: b * 10)
384+
}
385+
}
386+
struct DefaultArgumentsInExtensionImpl: DefaultArgumentsInExtension {
387+
func foo(a: Int, b: Int) -> (Int, Int) {
388+
(a * 2, b * 2)
389+
}
390+
}
391+
392+
ProtocolExtensionTestSuite.test("DefaultArgumentsInExtension") {
393+
let instance = DefaultArgumentsInExtensionImpl()
394+
expectEqual((4, 6), instance.foo(a: 2, b: 3))
395+
expectEqual((4, 6), (instance as any DefaultArgumentsInExtension).foo(a: 2, b: 3))
396+
expectEqual((40, 20), instance.foo(a: 2))
397+
expectEqual((40, 20), (instance as any DefaultArgumentsInExtension).foo(a: 2))
398+
}

0 commit comments

Comments
 (0)