Skip to content

[Observation] Ensure type access is qualified to the module name #66364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/Macros/Sources/ObservationMacros/ObservableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ import SwiftSyntaxMacros
@_implementationOnly import SwiftSyntaxBuilder

public struct ObservableMacro {
static let moduleName = "_Observation"

static let conformanceName = "Observable"
static var qualifiedConformanceName: String {
return "\(moduleName).\(conformanceName)"
}

static var observableConformanceType: TypeSyntax {
"\(raw: qualifiedConformanceName)"
}

static let registrarTypeName = "ObservationRegistrar"
static var qualifiedRegistrarTypeName: String {
return "\(moduleName).\(registrarTypeName)"
}

static let trackedMacroName = "ObservationTracked"
static let ignoredMacroName = "ObservationIgnored"

Expand All @@ -25,7 +41,7 @@ public struct ObservableMacro {
static func registrarVariable(_ observableType: TokenSyntax) -> DeclSyntax {
return
"""
@\(raw: ignoredMacroName) private let \(raw: registrarVariableName) = ObservationRegistrar()
@\(raw: ignoredMacroName) private let \(raw: registrarVariableName) = \(raw: qualifiedRegistrarTypeName)()
"""
}

Expand Down Expand Up @@ -264,13 +280,13 @@ extension ObservableMacro: ConformanceMacro {

if let inheritanceList {
for inheritance in inheritanceList {
if inheritance.typeName.identifier == "Observable" {
if inheritance.typeName.identifier == ObservableMacro.conformanceName {
return []
}
}
}

return [("Observable", nil)]
return [(ObservableMacro.observableConformanceType, nil)]
}
}

Expand Down