|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-build-swift -emit-executable -DTEST_EQUATABLE -o %t/InvalidStrideableEq %s |
| 3 | +// RUN: ! %target-run %t/InvalidStrideableEq 2>&1 | %FileCheck %s --check-prefix=CHECK-EQUATABLE |
| 4 | +// RUN: %target-build-swift -emit-executable -DTEST_COMPARABLE -o %t/InvalidStrideableCmp %s |
| 5 | +// RUN: ! %target-run %t/InvalidStrideableCmp 2>&1 | %FileCheck %s --check-prefix=CHECK-COMPARABLE |
| 6 | +// REQUIRES: executable_test |
| 7 | + |
| 8 | +// |
| 9 | +// Check that a circular Strideable inheriting witnesses from Stdlib crashes |
| 10 | +// with a rich error message. |
| 11 | +// |
| 12 | + |
| 13 | +struct InvalidStrideable : Strideable, SignedNumeric { |
| 14 | + typealias Magnitude = InvalidStrideable |
| 15 | + init?<T>(exactly: T) where T : BinaryInteger { return nil } |
| 16 | + var magnitude: InvalidStrideable { return self } |
| 17 | + |
| 18 | + static func += (lhs: inout InvalidStrideable, rhs: InvalidStrideable) { } |
| 19 | + static func -= (lhs: inout InvalidStrideable, rhs: InvalidStrideable) { } |
| 20 | + static func *= (lhs: inout InvalidStrideable, rhs: InvalidStrideable) { } |
| 21 | + |
| 22 | + static func + (lhs: InvalidStrideable, rhs: InvalidStrideable) -> InvalidStrideable { return rhs } |
| 23 | + static func - (lhs: InvalidStrideable, rhs: InvalidStrideable) -> InvalidStrideable { return rhs } |
| 24 | + static func * (lhs: InvalidStrideable, rhs: InvalidStrideable) -> InvalidStrideable { return rhs } |
| 25 | + |
| 26 | + typealias IntegerLiteralType = Int |
| 27 | + init(integerLiteral : Int) {} |
| 28 | + |
| 29 | + typealias Stride = InvalidStrideable |
| 30 | + |
| 31 | + init() {} |
| 32 | + |
| 33 | + func distance(to rhs: InvalidStrideable) -> InvalidStrideable { return self } |
| 34 | + func advanced(by n: InvalidStrideable) -> InvalidStrideable { return self } |
| 35 | +} |
| 36 | + |
| 37 | +#if TEST_EQUATABLE |
| 38 | + // CHECK-EQUATABLE: fatal error: Strideable conformance where 'Stride == Self' requires user-defined implementation of the '==' operator |
| 39 | + _ = InvalidStrideable() == InvalidStrideable() |
| 40 | +#else |
| 41 | + // CHECK-COMPARABLE: fatal error: Strideable conformance where 'Stride == Self' requires user-defined implementation of the '<' operator |
| 42 | + _ = InvalidStrideable() < InvalidStrideable() // Will trap with error message |
| 43 | +#endif |
0 commit comments