mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
using archetypes so that, e.g., an archetype T that conforms to Ordered can be compared with <. Requires the introduction of 'archetype' constraints, so that we don't run amok and allow the use of operators in protocols for *any* type that meets the requirements of the protocol. This may change later, with default implementations, of course. The egregious hack introduced in Char.isSpace() works around known, massive performance problems with the solver's exploration of the state space. In this case, we have 6 instances of ==, each of which has 18 overloads, for a large state space. However, we compound the problem significantly by trying many possibilities for the ~30 type variables in each state, rather than concluding quickly (as we should) that most of those branches don't make sense. Swift SVN r2922
27 lines
569 B
Swift
27 lines
569 B
Swift
// RUN: %swift -parse -verify -constraint-checker %s
|
|
|
|
protocol ConcatToAnything {
|
|
func [infix] +++ <T>(lhs : This, other : T)
|
|
}
|
|
|
|
func min<T : Ordered>(x : T, y : T) -> T {
|
|
if y < x { return y }
|
|
return x
|
|
}
|
|
|
|
func weirdConcat<T : ConcatToAnything, U>(t : T, u : U) {
|
|
t +++ u
|
|
t +++ 1
|
|
u +++ t // expected-error{{expression does not type-check}}
|
|
}
|
|
|
|
// Make sure that the protocol operators don't get in the way.
|
|
var b1, b2 : Bool
|
|
b1 != b2
|
|
|
|
extension Char {
|
|
func isAlpha2() -> Bool {
|
|
return (this >= 'A' && this <= 'Z') || (this >= 'a' && this <= 'z')
|
|
}
|
|
}
|