<commit_before>// RUN: %target-typecheck-verify-swift -enable-objc-interop

import Foundation

let ok = "A" as Character // OK
let succeed = "A" as? String // expected-warning {{always succeeds}}
let bad = "A" as? Character // expected-warning {{conditional downcast from literal to 'Character' always fails; consider using 'as' coercion}} {{none}}
let bad2 = "Aa" as? Character // expected-warning {{cast from 'String' to unrelated type 'Character' always fails}}
let bad1 = 1 as? Character // expected-warning {{cast from 'Int' to unrelated type 'Character' always fails}}

let okInt = 1 as Int // OK
let badInt = 1 as? Int // expected-warning {{always succeeds}}
let badInt1 = 1.0 as? Int // expected-warning {{cast from 'Double' to unrelated type 'Int' always fails}}
let badInt2 = 1 as? Double // expected-warning {{conditional downcast from literal to 'Double' always fails; consider using 'as' coercion}} {{none}}

let okUInt = 1 as UInt // OK
let badUInt = 1 as? UInt // expected-warning {{conditional downcast from literal to 'UInt' always fails; consider using 'as' coercion}} {{none}}
let badUInt1 = 1.0 as? UInt // expected-warning {{cast from 'Double' to unrelated type 'UInt' always fails}}

// Can downcast by bridging
let bridge = "A" as? NSString // expected-warning {{always succeeds}}
let bridge1 = 1 as? NSNumber // expected-warning {{always succeeds}}

// Custom protocol adoption
struct S: ExpressibleByStringLiteral {
  typealias StringLiteralType = String
  init(stringLiteral value: Self.StringLiteralType) {}
}

let a = "A" as? S // expected-warning {{conditional downcast from literal to 'S' always fails; consider using 'as' coercion}} {{none}}
<commit_msg>Require objc interop on cast/literals_downcast tests<commit_after>// RUN: %target-typecheck-verify-swift -enable-objc-interop
// REQUIRES: objc_interop

import Foundation

let ok = "A" as Character // OK
let succeed = "A" as? String // expected-warning {{always succeeds}}
let bad = "A" as? Character // expected-warning {{conditional downcast from literal to 'Character' always fails; consider using 'as' coercion}} {{none}}
let bad2 = "Aa" as? Character // expected-warning {{cast from 'String' to unrelated type 'Character' always fails}}
let bad1 = 1 as? Character // expected-warning {{cast from 'Int' to unrelated type 'Character' always fails}}

let okInt = 1 as Int // OK
let badInt = 1 as? Int // expected-warning {{always succeeds}}
let badInt1 = 1.0 as? Int // expected-warning {{cast from 'Double' to unrelated type 'Int' always fails}}
let badInt2 = 1 as? Double // expected-warning {{conditional downcast from literal to 'Double' always fails; consider using 'as' coercion}} {{none}}

let okUInt = 1 as UInt // OK
let badUInt = 1 as? UInt // expected-warning {{conditional downcast from literal to 'UInt' always fails; consider using 'as' coercion}} {{none}}
let badUInt1 = 1.0 as? UInt // expected-warning {{cast from 'Double' to unrelated type 'UInt' always fails}}

// Can downcast by bridging
let bridge = "A" as? NSString // expected-warning {{always succeeds}}
let bridge1 = 1 as? NSNumber // expected-warning {{always succeeds}}

// Custom protocol adoption
struct S: ExpressibleByStringLiteral {
  typealias StringLiteralType = String
  init(stringLiteral value: Self.StringLiteralType) {}
}

let a = "A" as? S // expected-warning {{conditional downcast from literal to 'S' always fails; consider using 'as' coercion}} {{none}}

{'fraction_non_alphanumeric': 0.12343522561863174, 'fraction_numerical': 0.009898107714701601, 'mean_word_length': 4.40251572327044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1871061', 'n_tokens_mistral': 1014, 'n_tokens_neox': 945, 'n_words': 423}