Public enum inaccessible due to @_spi isolation level error

For context I’m working on a wrapper for a C++ library.

I havepublic enum PMXEventSubscriptionRequest: Hashable, Sendable used for event registration. Well, event registration takes a struct that has that enum, a string and a callback that will be called when the event arrives.

When I was writing a test case (using an Xcode app that depended on the tested package) I got an error saying that the enum in question was “inaccessible due to @_spi isolation level” when I fully qualified the case. Omitting the type name worked fine, as well as all further uses after that one.

I thought it might be due to using a local dependency, but the behaviour is the same when I depend on the repository.

Though I also found that If I use a case that only has a public enum LibEventType:Int64, Sendable as an associated value, the workaround fails, giving me “Cannot infer contextual base in reference to member” (instead of the @_spi error message) and adds cannot be constructed because it has no accessible initializers.

However in both cases adding let x:PMXEventSubscriptionRequest just above the problematic call makes the errors go away.

Here’s a minimal(-ish) example: a clean package with swift package init, added dependency to the wrapper at .upToNextMinor(from: .init(2, 6, 0,prereleaseIdentifiers: ["rc5"]))

and put below in the source

import Foundation
import PrivMXEndpointSwiftExtra
import PrivMXEndpointSwiftNative

class PrivMXSnippetClass {
	var endpointSession: PrivMXEndpoint?
	
	func handlingConnectionEvents(){
		//let x:PMXEventSubscriptionRequest //uncommenting this will make the errors go away
		
		
		// uncomment the call to change errors
		//try? endpointSession?.registerCallback(
		//	for: PMXEventCallbackRegistration.init(
		//		request:.library(eventType: LibEventType.LIB_CONNECTED),
		//		group: "Some_group"){_ in})
		
		try? endpointSession?.registerCallback(
			for: PMXEventCallbackRegistration.init(
				request:PMXEventSubscriptionRequest.core( //'PMXEventSubscriptionRequest' is inaccessible due to '@_spi' protection level
				//request:.core( //swap with above to remove error
					eventType: privmx.endpoint.core.USER_STATUS,
					contextId: "some_ID"),
				group: "Some_group"){_ in})

		try? endpointSession?.registerCallback(
			for: PMXEventCallbackRegistration.init(
				request:PMXEventSubscriptionRequest.thread(
					eventType: privmx.endpoint.thread.THREAD_UPDATE,
					selectorType: .Container,
					selectorId: "other_ID"),
				group: "Some_group"){_ in})
	}
}

swift build outputs this:

/PathToPackage/Sources/Target/File.swift:21:13 error: 'PMXEventSubscriptionRequest' is inaccessible due to '@_spi' protection level
19 | 		try? endpointSession?.registerCallback(
20 | 			for: PMXEventCallbackRegistration.init(
21 | 				request:PMXEventSubscriptionRequest.core(
   |             `- error: 'PMXEventSubscriptionRequest' is inaccessible due to '@_spi' protection level
22 | 				//request:.core( //uncomment this and uncomment the one above to remove error
23 | 					eventType: privmx.endpoint.core.USER_STATUS,

/PathToPackage/.build/checkouts/privmx-endpoint-swift-extra/Sources/PrivMXEndpointSwiftExtra/Core/PMXEventCallbackRegistration.swift:79:13: note: 'PMXEventSubscriptionRequest' declared here
 77 | 
 78 | /// Enum handling proper registrations for events.
 79 | public enum PMXEventSubscriptionRequest: Hashable, Sendable{
    |             `- note: 'PMXEventSubscriptionRequest' declared here
 80 | 	public static func == (lhs: PMXEventSubscriptionRequest, rhs: PMXEventSubscriptionRequest) -> Bool {
 81 | 		switch (lhs,rhs){


Swift version:

swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx26.0

As a side note, I’ve also had some issues with symbols being “overlooked” by the compiler. This feels like it’s somewhat connected, but I’m not sure.

Is this a known bug?
Or am I doing something wrong?

I’ve went ahead and created an issue for this: public enum inaccessible due to `@_spi` isolation level · Issue #84710 · swiftlang/swift · GitHub

1 Like