Skip to content

Extensions for subtype of a class marked @Observable generate compile error #66450

@virasio

Description

@virasio

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

@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:

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.circular referenceBug → internal error: Circular referencecompilerThe Swift compiler itselfinternal errorBug: Internal errornested typesFeature: nested typesswift 5.9swift macroFeature → declarations: Swift `macro` declarationstype checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions