The code below is located in the application module:
enum API {}
extension API {
protocol Endpoint: Sendable {
var basePath: String { get }
var apiName: String { get }
var urlComponents: URLComponents? { get }
}
}
extension API.Endpoint {
var basePath: String { "/api/v2/" }
}
extension API {
enum AutorizationEndpoint: String {
case login
case logout
}
}
extension API.AutorizationEndpoint: API.Endpoint {
var apiName: String { "auth/" }
var urlComponents: URLComponents? {
let path = basePath + apiName + rawValue
return URLComponents(string: path)
}
}
Now I want to test:
@Test("Endpoint URLComponents validation", arguments: [
API.AutorizationEndpoint.login,
API.AutorizationEndpoint.logout,
])
func testComponentsNotNil(_ endpoint: API.Endpoint) {
#expect(endpoint.urlComponents != nil)
}
However, the compiler produces the following error:
Main actor-isolated property 'urlComponents' cannot be accessed from outside of the actor
Why? What happened? I don't mark any protocol or enum with @MainActor directly. This is a fairly simple test and there shouldn't be any problems with it.
Environment: macOS 26.1; Exode 26.1.1; Swift 6