Files
swift-mirror/test/Macros/Inputs/macro_library.swift
Henrik G. Olsson efd70b1f54 Prevent silgen for macro expansions with type errors (#81396)
Due to a bug in how macros on nodes imported from clang are evaluated,
their function body is not always type checked. This forces type
checking before silgen of a macro originating on a node imported from
clang, to prevent crashing in silgen.

rdar://150940383
2025-05-09 10:27:27 -07:00

72 lines
2.4 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)
@attached(extension, conformances: Observable)
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")
@propertyWrapper
public struct declareVarValuePeerShadowed {
public var wrappedValue: Int
public init(wrappedValue: Int) {
self.wrappedValue = wrappedValue
}
}
@attached(peer, names: named(value))
public macro declareVarValuePeerShadowed() = #externalMacro(module: "MacroDefinition", type: "VarValueMacro")
@attached(peer, names: overloaded)
public macro AddAsync() = #externalMacro(module: "MacroDefinition", type: "AddAsyncMacro")
@attached(peer, names: overloaded)
public macro AddAsyncFinal() = #externalMacro(module: "MacroDefinition", type: "AddAsyncMacro")
public enum Something {
case something
}
@attached(peer, names: overloaded)
public macro AcceptedDotted(_: Something) = #externalMacro(module: "MacroDefinition", type: "EmptyPeerMacro")
@attached(peer, names: overloaded)
public macro ExpandTypeError() = #externalMacro(module: "MacroDefinition", type: "ExpandTypeErrorMacro")