li3zhen1
(li3zhen1)
October 25, 2023, 6:58pm
1
Hi!
I've been working on macros recently. Here's a macro that replaces a generic parameter and puts a new specialized version alongside the original type.
The code without extension part compiles, but it produces circular reference error when adding the extension. And if I move the extension to another file, code compiles.
I did some search and only found this: https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md#restrictions-on-arbitrary-names , but not sure if they are actually the same situation.
Is it by design or some bug?
li3zhen1
(li3zhen1)
October 25, 2023, 7:03pm
2
This might be related to this bug, which has had quite a bit of discussion, though none from the team yet, and it hasn't been triaged.
opened 02:53PM - 08 Jun 23 UTC
bug
triage needed
**Description**
I cannot add a subtype (class, enum, struct) to a class marked … with `@Observable` macro. If I add an extension to this subtype, I get compile error:
> Circular reference resolving attached macro 'Observable'
**Steps to reproduce**
```swift
@Observable
class MyObservableClass {
var property1 = ""
var property2 = MyClass()
}
extension MyObservableClass {
class MyClass {
var property = ""
}
}
extension MyObservableClass.MyClass {
var test: String { "test \(property)" }
}
```
**Expected behavior**
It must be compilable because the following version is compilible:
```swift
@Observable
class MyObservableClass {
var property1 = ""
var property2 = MyClass()
}
extension MyObservableClass {
class MyClass {
var property = ""
var test: String { "test \(property)" }
}
}
```
**Environment**
Xcode 15.0 beta (15A5160n)
Swift 5.9
Target: iOS 17.0