Avatar
Avatar
rintaro
Array 以外でも再現するので (Stringと Int 確認しました)、リテラル系はとりあえずオーバーロード用意しておいたほうが良さそうですね。 とはいえ ユーザ定義の *LiteralExpressible だと失敗しそう。 TypeChecker の人がバグと判断するかはわかりませんが、issueたてていただけるとありがたいです。 @swift-5.8.1 func id<T>(_ val: T) -> T { val } func test(c: Character) { id("").first != c } (edited)
swift58 BOT 4/9/2023 2:30 AM
exit status: 1 with <stdin>:4:10: error: value of optional type 'String.Element?' (aka 'Optional<Character>') must be unwrapped to a value of type 'String.Element' (aka 'Character') id("").first != c ^ <stdin>:4:10: note: coalesce using '??' to provide a default when the optional value contains 'nil' id("").first != c ^ ?? <#default value#> <stdin>:4:10: note: force-unwrap using '!' to abort execution if the optional value contains 'nil' id("").first != c ^ !