Emitting warning when creating instance of type conforming to protocol

Hi all

I've been looking at whether it is possible to emit a warning into Xcode when instantiating a type that conforms to a specific protocol.

I can see that using SwiftSyntax, I could emit a warning when declaring the type by inspecting the inheritance syntax node. This is potentially better than nothing, but what I would really like to achieve is emitting a warning when instantiating something that conforms to a specific protocol.

For example:

protocol HandleWithCare { }

struct HereBeDragons: HandleWithCare { }

... 

// in some other library or target

let item = HereBeDragons() // ⚠️ warning displayed here in Xcode

I've done a bit of reading around this and have yet to identify a way to achieve what I'm after but it feels like it should be possible.

I'm not wedded to the idea of attaching the warning emitter via protocol conformance. If there's another way that achieves the same effect that would be good to explore.

Do any of you have any suggestions for approaches to take and things to investigate?

You could try @_spi but not sure it exactly what you are searching for :thinking:

Thanks for this. It is interesting; I've not used it before. It does part of what I want which is to force people to knowingly use something that's potentially problematic or has an unstable API.

It's good for the initial use but there's no on-going warning about using it for the consuming developer(s).

I suppose a custom SwiftLint rule or such like could deal with that.

Do you have any experience of using @_spi in production apps? I'm slightly concerned about App review not liking the underscore.

For me none but I think the swift syntax package uses it