Avatar
Avatar
norio_nomura
ああ勘違いしていました。enumの場合、そもそもジェネリックパラメータ違いのものをcaseでマッチできないんだ。func ~=を提供すれば使えると思ってた。 @swift-main enum O<W> { case some(W) static func ~=<L, R> (l: O<L>, r: O<R>) -> Bool { return true } } if case O<Double>.some(..<0) = O<Int>.some(-1) { print("OK") }
swiftNightly BOT 1/30/2025 9:28 AM
exit status: 1 with <stdin>:5:39: error: cannot assign value of type 'O<Int>' to type 'O<Double>' 1 | enum O<W> { | `- note: arguments to generic parameter 'W' ('Int' and 'Double') are expected to be equal 2 | case some(W) 3 | static func ~=<L, R> (l: O<L>, r: O<R>) -> Bool { return true } 4 | } 5 | if case O<Double>.some(..<0) = O<Int>.some(-1) { print("OK") } | `- error: cannot assign value of type 'O<Int>' to type 'O<Double>' 6 |