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