<commit_before># `where` clauses on contextually generic declarations

* Proposal: [SE-0267](0267-where-on-contextually-generic.md)
* Author: [<NAME>](https://github.com/AnthonyLatsis)
* Review Manager: [<NAME>](https://github.com/jckarter)
* Status: **Active review (October 21...October 31)**
* Implementation: [apple/swift#23489](https://github.com/apple/swift/pull/23489)

## Introduction

This proposal aims to lift the mostly artificial restriction on attaching `where` clauses to declarations that reference only outer generic parameters. Simply put, this means you no longer have to worry about the `'where' clause cannot be attached` error inside most generic contexts.

```swift
struct Box<Wrapped> {
    func sequence() -> [Box<Wrapped.Element>] where Wrapped: Sequence { ... }
}

```

> Only declarations that already support a generic parameter list will be allowed to carry a `where` clause inside a generic 
> context. Generic properties and constraints on protocol requirements are out of scope for the current proposal.
> For instance, the following remains an error:
> ```swift
> protocol P {
>     // error: Instance method requirement 'foo(arg:)' cannot add constraint 'Self: Equatable' on 'Self'
>     func foo() where Self: Equatable  
> }
> ```
> Whereas placing a constraint on an extension member rather than the extension itself becomes possible:
> ```swift
> extension P {<commit_msg>SE-0267 was accepted<commit_after># `where` clauses on contextually generic declarations

* Proposal: [SE-0267](0267-where-on-contextually-generic.md)
* Author: [<NAME>](https://github.com/AnthonyLatsis)
* Review Manager: [<NAME>](https://github.com/jckarter)
* Status: **Accepted**
* Implementation: [apple/swift#23489](https://github.com/apple/swift/pull/23489)

## Introduction

This proposal aims to lift the mostly artificial restriction on attaching `where` clauses to declarations that reference only outer generic parameters. Simply put, this means you no longer have to worry about the `'where' clause cannot be attached` error inside most generic contexts.

```swift
struct Box<Wrapped> {
    func sequence() -> [Box<Wrapped.Element>] where Wrapped: Sequence { ... }
}

```

> Only declarations that already support a generic parameter list will be allowed to carry a `where` clause inside a generic 
> context. Generic properties and constraints on protocol requirements or nonfinal class methods are out of scope for the current proposal.
> For instance, the following remains an error:
> ```swift
> protocol P {
>     // error: Instance method requirement 'foo(arg:)' cannot add constraint 'Self: Equatable' on 'Self'
>     func foo() where Self: Equatable  
> }
>
> class C {
>     // error: Nonfinal method 'foo(arg:)' cannot add constraint 'Self: Equatable' on 'Self'
>     func foo() where Self: Equatable  
> }
> ```
> Whereas placing a constraint on an extension member rather than the extension itself becomes possible:
> ```swift
> extension P {
{'fraction_non_alphanumeric': 0.10984212294255963, 'fraction_numerical': 0.014779979845482029, 'mean_word_length': 4.694072657743786, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5387942', 'n_tokens_mistral': 845, 'n_tokens_neox': 780, 'n_words': 337}