Files
swift-mirror/test/Macros/Inputs/macro_library.swift
Richard Wei 9c91d1b705 [Macros] Fix lookup of macro-produced variables (#65939)
Calling `getInnermostDeclContext()->getParentSourceFile()` on a macro-produced decl does not seem to be a reliable way to obtain the macro expansion source file, because `PatternBindingDecl` is not a `DeclContext` and `getInnermostDeclContext()` falls back outside the macro expansion file. This patch switches to using `getSourceFileContainingLocation` when possible.

Resolves rdar://109376568.
2023-05-18 15:32:21 -07:00

44 lines
1.5 KiB
Swift

public protocol Observable {}
public protocol Observer<Subject> {
associatedtype Subject: Observable
}
public struct ObservationRegistrar<Subject: Observable> {
public init() {}
public func addObserver(_ observer: some Observer<Subject>) {}
public func removeObserver(_ observer: some Observer<Subject>) {}
public func beginAccess<Value>(_ keyPath: KeyPath<Subject, Value>) {}
public func beginAccess() {}
public func endAccess() {}
public func register<Value>(observable: Subject, willSet: KeyPath<Subject, Value>, to: Value) {}
public func register<Value>(observable: Subject, didSet: KeyPath<Subject, Value>) {}
}
@attached(
member,
names: named(_registrar), named(addObserver), named(removeObserver), named(withTransaction), named(Storage), named(_storage)
)
@attached(memberAttribute)
public macro Observable() = #externalMacro(module: "MacroDefinition", type: "ObservableMacro")
@attached(accessor)
public macro ObservableProperty() = #externalMacro(module: "MacroDefinition", type: "ObservablePropertyMacro")
@attached(peer, names: overloaded)
public macro addCompletionHandler() = #externalMacro(module: "MacroDefinition", type: "AddCompletionHandler")
@attached(peer, names: suffixed(Builder))
public macro AddClassReferencingSelf() = #externalMacro(module: "MacroDefinition", type: "AddClassReferencingSelfMacro")
@attached(peer, names: named(value))
public macro declareVarValuePeer() = #externalMacro(module: "MacroDefinition", type: "VarValueMacro")