Avatar
Avatar
ジュニア
@swift-5.9.2 protocol P {} struct MySet<Element: Hashable> {} struct MyArray<Element> { func set() -> MySet<Element> where Element: P { .init() } } class NonHashable {} func foo() { let array = MyArray<NonHashable>() array.set() }
exit status: 1 with <stdin>:16:11: error: instance method 'set()' requires that 'NonHashable' conform to 'Hashable' array.set() ^ <stdin>:7:10: note: where 'Element' = 'NonHashable' func set() -> MySet<Element> where Element: P { ^ <stdin>:16:11: error: instance method 'set()' requires that 'NonHashable' conform to 'P' array.set() ^ <stdin>:7:10: note: where 'Element' = 'NonHashable' func set() -> MySet<Element> where Element: P { ^