mhavu
(Marko Havu)
February 17, 2019, 5:18pm
1
The following fails, because Silver requires test_passes
and test_fails
to be static:
class MyTestCase: XCTestCase {
static var allTests = {
return [
("test_passes", test_passes), // E: "test_passes" is not static
("test_fails", test_fails), // E: "test_fails" is not static
]
}()
func test_passes() {
XCTAssert(true)
}
func test_fails() {
XCTAssert(false)
}
}
mh
(marc hoffman)
February 17, 2019, 7:38pm
2
Hmm. I don’t see how they could not be required to. a static method/property, allTests
cannot access/call instance members of a type.
what should this compile to? what’t the (implied) return type of allTests, an array of tuples of a string and what exactly?
mhavu
(Marko Havu)
February 17, 2019, 7:55pm
3
mh:
Hmm. I don’t see how they could not be required to. a static method/property, allTests
cannot access/call instance members of a type.
what should this compile to? what’t the (implied) return type of allTests, an array of tuples of a string and what exactly?
Yeah, I was thinking about this, too. I couldn’t find the right part of the language spec to see what is supposed to happen here, but this is how Apple writes their test cases. With their compiler allTests
is of type [(String, (MyTestCase) -> () -> ())]
.
ck
(Carlo Kok)
February 18, 2019, 6:32am
5
Curious, why the double delegate? In any case it seems that Swift allows (MyTestcase) -> ()
to point to a static method and call it through that.
So basically this:
typealias test = (MyClass) -> ()
class MyClass {
static var inst: test = TakeThis;
func TakeThis() {
}
}
should work. I’ll create an issue.
Thanks, logged as bugs://81986
bugs://81986 got closed with status fixed.
mhavu
(Marko Havu)
February 18, 2019, 9:49am
8
ck:
Curious, why the double delegate? In any case it seems that Swift allows (MyTestcase) -> ()
to point to a static method and call it through that.
So basically this:
typealias test = (MyClass) -> ()
class MyClass {
static var inst: test = TakeThis;
func TakeThis() {
}
}
should work. I’ll create an issue.
Apple’s compiler is not happy with the above:
Cannot convert value of type '(MyClass) -> () -> ()' to specified type 'test' (aka '(MyClass) -> ()')
ck
(Carlo Kok)
February 18, 2019, 12:38pm
9
hrmm this is quite odd. From the error it seems it returns a delegate that takes an instance of the class and returns delegate. Fairly indirect. Ill investigate further.