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?