<commit_before>// RUN: %target-swift-frontend -typecheck -verify %S/Inputs/keypath.swift -primary-file %s -swift-version 5

struct S {
  let i: Int

  init() {
    let _: WritableKeyPath<S, Int> = \.i // expected-error {{cannot convert value of type 'KeyPath<S, Int>' to specified type 'WritableKeyPath<S, Int>'}}

    S()[keyPath: \.i] = 1
    // expected-error@-1 {{cannot assign through subscript: immutable key path}}
  }
}

func test() {
  let _: WritableKeyPath<C, Int> = \.i // expected-error {{cannot convert value of type 'KeyPath<C, Int>' to specified type 'WritableKeyPath<C, Int>'}}

  C()[keyPath: \.i] = 1
  // expected-error@-1 {{cannot assign through subscript: immutable key path}}

  let _ = C()[keyPath: \.i] // no warning for a read
}<commit_msg>Test: Update swift 5 keypath tests to reflect and test new behavior<commit_after>// RUN: %target-swift-frontend -typecheck -verify %S/Inputs/keypath.swift -primary-file %s -swift-version 5

struct S {
  let i: Int

  init() {
    let _: WritableKeyPath<S, Int> = \.i // expected-error {{cannot convert value of type 'KeyPath<S, Int>' to specified type 'WritableKeyPath<S, Int>'}}

    S()[keyPath: \.i] = 1
    // expected-error@-1 {{cannot assign through subscript: the key path is a read-only key path}}
  }
}

func test() {
  let _: WritableKeyPath<C, Int> = \.i // expected-error {{cannot convert value of type 'KeyPath<C, Int>' to specified type 'WritableKeyPath<C, Int>'}}

  C()[keyPath: \.i] = 1
  // expected-error@-1 {{cannot assign through subscript: the key path is a read-only key path}}

  let _ = C()[keyPath: \.i] // no warning for a read
}


struct T {
    private(set) var a: Int
    init(a: Int) {
        self.a = a
    }
}

func testReadOnlyKeyPathDiagnostics() {
  let path = \T.a
  var t = T(a: 3)
  t[keyPath: path] = 4 // expected-error {{cannot assign through subscript: 'path' is a read-only key path}}
  t[keyPath: \T.a] = 4 // expected-error {{cannot assign through subscript: the key path is a read-only key path}}
}
{'fraction_non_alphanumeric': 0.15208747514910537, 'fraction_numerical': 0.006958250497017893, 'mean_word_length': 3.264830508474576, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '396671', 'n_tokens_mistral': 723, 'n_tokens_neox': 685, 'n_words': 244}