Skip to content

Commit feb1401

Browse files
committed
Sema: Add test for operator returning Self
We didn't have a test for it, as I discovered while adding some assertions.
1 parent 26bf98f commit feb1401

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/decl/func/dynamic_self.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,23 @@ final class FinalFactory : FactoryPattern {
393393
self.init(factory: FinalFactory(_string: string))
394394
}
395395
}
396+
397+
// Operators returning Self
398+
399+
class SelfOperator {
400+
required init() {}
401+
402+
static func +(lhs: SelfOperator, rhs: SelfOperator) -> Self {
403+
return self.init()
404+
}
405+
406+
func double() -> Self {
407+
// FIXME: Should this work?
408+
return self + self // expected-error {{cannot convert return expression of type 'SelfOperator' to return type 'Self'}}
409+
}
410+
}
411+
412+
func useSelfOperator() {
413+
let s = SelfOperator()
414+
_ = s + s
415+
}

0 commit comments

Comments
 (0)