Files
swift-mirror/test/decl/protocol/protocol_with_default_args.swift
Rintaro Ishizaki 8a58107123 [Parse] Diagnose default argument for subscript in protocols
Protocol requirements don't support default arguments. Although this is
a "semantic" diagnostics, we currently do this for 'func' and 'init' in
Parser. So for fixing a crash, let's to it for 'subscript' in Parser
too.

rdar://problem/73159041
2021-01-22 17:21:17 -08:00

16 lines
473 B
Swift

// RUN: %target-typecheck-verify-swift
protocol P {
func foo(_ truth: Bool = false) // expected-error{{default argument not permitted in a protocol method}}
}
struct X : P {
func foo(_ truth: Bool = false) {
}
}
protocol Q {
init(truth: Bool = false) // expected-error{{default argument not permitted in a protocol initializer}}
subscript(x: Int, default: Int = 0) -> Self { get } // expected-error {{default argument not permitted in a protocol subscript}}
}