Skip to content
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

SymbolGraphGen emits synthesized symbols for types inherited from protocols, but not types inherited from base classes. #63698

Open
tayloraswift opened this issue Feb 15, 2023 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.

Comments

@tayloraswift
Copy link
Member

tayloraswift commented Feb 15, 2023

test file:

/// Swift types can inherit typealiases from the protocols they
/// conform to. Subclasses can also inherit types (including
/// typealiases) from the base classes; if they are overloaded,
/// the base class's declaration wins. 
public
class Base
{
}

extension Base
{
    public
    enum Inner
    {
    }
}

public
protocol Interface
{
}
extension Interface
{
    public
    typealias Inner = UInt8

    public
    typealias Other = Int8
}

public
class BaseDerived:Base, Interface
{
}

extension BaseDerived
{
    public
    struct Shadowed
    {
    }
}
extension BaseDerived
{
    public
    typealias Preferred = BaseDerived.Inner
    public
    typealias Inherited = BaseDerived.Other
}

observed symbolgraph-extract output:

{
  "metadata": {
    "formatVersion": {
      "major": 0,
      "minor": 6,
      "patch": 0
    },
    "generator": "Swift version 5.8-dev (LLVM 44d4f9d4b49845f, Swift 40e02c02ad5b3bb)"
  },
  "module": {
    "name": "ZooInheritedTypePrecedence",
    "platform": {
      "architecture": "x86_64",
      "environment": "gnu",
      "vendor": "unknown",
      "operatingSystem": {
        "name": "linux"
      }
    }
  },
  "symbols": [
    {
      "kind": {
        "identifier": "swift.typealias",
        "displayName": "Type Alias"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence11BaseDerivedC9Preferreda",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "BaseDerived",
        "Preferred"
      ],
      "names": {
        "title": "BaseDerived.Preferred",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Preferred"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "typealias"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Preferred"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.class"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "typealias"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Preferred"
        },
        {
          "kind": "text",
          "spelling": " = "
        },
        {
          "kind": "typeIdentifier",
          "spelling": "Base",
          "preciseIdentifier": "s:26ZooInheritedTypePrecedence4BaseC"
        },
        {
          "kind": "text",
          "spelling": "."
        },
        {
          "kind": "typeIdentifier",
          "spelling": "Inner",
          "preciseIdentifier": "s:26ZooInheritedTypePrecedence4BaseC5InnerO"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 45,
          "character": 14
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.typealias",
        "displayName": "Type Alias"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Innera",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "Interface",
        "Inner"
      ],
      "names": {
        "title": "Interface.Inner",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Inner"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "typealias"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Inner"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.protocol"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "typealias"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Inner"
        },
        {
          "kind": "text",
          "spelling": " = "
        },
        {
          "kind": "typeIdentifier",
          "spelling": "UInt8",
          "preciseIdentifier": "s:s5UInt8V"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 24,
          "character": 14
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.typealias",
        "displayName": "Type Alias"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Innera::SYNTHESIZED::s:26ZooInheritedTypePrecedence11BaseDerivedC",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "BaseDerived",
        "Inner"
      ],
      "names": {
        "title": "BaseDerived.Inner",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Inner"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "typealias"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Inner"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.protocol"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "typealias"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Inner"
        },
        {
          "kind": "text",
          "spelling": " = "
        },
        {
          "kind": "typeIdentifier",
          "spelling": "UInt8",
          "preciseIdentifier": "s:s5UInt8V"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 24,
          "character": 14
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.protocol",
        "displayName": "Protocol"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence9InterfaceP",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "Interface"
      ],
      "names": {
        "title": "Interface",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Interface"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "protocol"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Interface"
          }
        ]
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "protocol"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Interface"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 18,
          "character": 9
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.typealias",
        "displayName": "Type Alias"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence11BaseDerivedC0B0a",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "BaseDerived",
        "Inherited"
      ],
      "names": {
        "title": "BaseDerived.Inherited",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Inherited"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "typealias"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Inherited"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.class"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "typealias"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Inherited"
        },
        {
          "kind": "text",
          "spelling": " = "
        },
        {
          "kind": "typeIdentifier",
          "spelling": "BaseDerived",
          "preciseIdentifier": "s:26ZooInheritedTypePrecedence11BaseDerivedC"
        },
        {
          "kind": "text",
          "spelling": "."
        },
        {
          "kind": "typeIdentifier",
          "spelling": "Other",
          "preciseIdentifier": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Othera"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 47,
          "character": 14
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.enum",
        "displayName": "Enumeration"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence4BaseC5InnerO",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "Base",
        "Inner"
      ],
      "names": {
        "title": "Base.Inner",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Inner"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "enum"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Inner"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.class"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "enum"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Inner"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 12,
          "character": 9
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.typealias",
        "displayName": "Type Alias"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Othera::SYNTHESIZED::s:26ZooInheritedTypePrecedence11BaseDerivedC",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "BaseDerived",
        "Other"
      ],
      "names": {
        "title": "BaseDerived.Other",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Other"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "typealias"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Other"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.protocol"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "typealias"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Other"
        },
        {
          "kind": "text",
          "spelling": " = "
        },
        {
          "kind": "typeIdentifier",
          "spelling": "Int8",
          "preciseIdentifier": "s:s4Int8V"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 27,
          "character": 14
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.class",
        "displayName": "Class"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence11BaseDerivedC",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "BaseDerived"
      ],
      "names": {
        "title": "BaseDerived",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "BaseDerived"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "class"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "BaseDerived"
          }
        ]
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "class"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "BaseDerived"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 31,
          "character": 6
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.typealias",
        "displayName": "Type Alias"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Othera",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "Interface",
        "Other"
      ],
      "names": {
        "title": "Interface.Other",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Other"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "typealias"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Other"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.protocol"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "typealias"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Other"
        },
        {
          "kind": "text",
          "spelling": " = "
        },
        {
          "kind": "typeIdentifier",
          "spelling": "Int8",
          "preciseIdentifier": "s:s4Int8V"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 27,
          "character": 14
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.struct",
        "displayName": "Structure"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence11BaseDerivedC8ShadowedV",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "BaseDerived",
        "Shadowed"
      ],
      "names": {
        "title": "BaseDerived.Shadowed",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Shadowed"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "struct"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Shadowed"
          }
        ]
      },
      "swiftExtension": {
        "extendedModule": "ZooInheritedTypePrecedence",
        "typeKind": "swift.class"
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "struct"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Shadowed"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 38,
          "character": 11
        }
      }
    },
    {
      "kind": {
        "identifier": "swift.class",
        "displayName": "Class"
      },
      "identifier": {
        "precise": "s:26ZooInheritedTypePrecedence4BaseC",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "Base"
      ],
      "names": {
        "title": "Base",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "Base"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "class"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Base"
          }
        ]
      },
      "docComment": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "module": "ZooInheritedTypePrecedence",
        "lines": [
          {
            "range": {
              "start": {
                "line": 0,
                "character": 4
              },
              "end": {
                "line": 0,
                "character": 63
              }
            },
            "text": "Swift types can inherit typealiases from the protocols they"
          },
          {
            "range": {
              "start": {
                "line": 1,
                "character": 4
              },
              "end": {
                "line": 1,
                "character": 60
              }
            },
            "text": "conform to. Subclasses can also inherit types (including"
          },
          {
            "range": {
              "start": {
                "line": 2,
                "character": 4
              },
              "end": {
                "line": 2,
                "character": 63
              }
            },
            "text": "typealiases) from the base classes; if they are overloaded,"
          },
          {
            "range": {
              "start": {
                "line": 3,
                "character": 4
              },
              "end": {
                "line": 3,
                "character": 41
              }
            },
            "text": "the base class’s declaration wins. "
          }
        ]
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "class"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Base"
        }
      ],
      "accessLevel": "public",
      "location": {
        "uri": "file:///swift/swift-biome/Zoo/InheritedTypePrecedence/InheritedTypePrecedence.swift",
        "position": {
          "line": 5,
          "character": 6
        }
      }
    }
  ],
  "relationships": [
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Othera",
      "target": "s:26ZooInheritedTypePrecedence9InterfaceP"
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence11BaseDerivedC9Preferreda",
      "target": "s:26ZooInheritedTypePrecedence11BaseDerivedC"
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence11BaseDerivedC0B0a",
      "target": "s:26ZooInheritedTypePrecedence11BaseDerivedC"
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Innera::SYNTHESIZED::s:26ZooInheritedTypePrecedence11BaseDerivedC",
      "target": "s:26ZooInheritedTypePrecedence11BaseDerivedC",
      "sourceOrigin": {
        "identifier": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Innera",
        "displayName": "Interface.Inner"
      }
    },
    {
      "kind": "inheritsFrom",
      "source": "s:26ZooInheritedTypePrecedence11BaseDerivedC",
      "target": "s:26ZooInheritedTypePrecedence4BaseC"
    },
    {
      "kind": "conformsTo",
      "source": "s:26ZooInheritedTypePrecedence11BaseDerivedC",
      "target": "s:26ZooInheritedTypePrecedence9InterfaceP"
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Othera::SYNTHESIZED::s:26ZooInheritedTypePrecedence11BaseDerivedC",
      "target": "s:26ZooInheritedTypePrecedence11BaseDerivedC",
      "sourceOrigin": {
        "identifier": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Othera",
        "displayName": "Interface.Other"
      }
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence9InterfacePAAE5Innera",
      "target": "s:26ZooInheritedTypePrecedence9InterfaceP"
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence4BaseC5InnerO",
      "target": "s:26ZooInheritedTypePrecedence4BaseC"
    },
    {
      "kind": "memberOf",
      "source": "s:26ZooInheritedTypePrecedence11BaseDerivedC8ShadowedV",
      "target": "s:26ZooInheritedTypePrecedence11BaseDerivedC"
    }
  ]
}

if inputted into a documentation engine, the documentation engine would show inherited typealiases from protocol conformances on the page for BaseDerived, but it would not show inherited types from Base. this is unexpected, because a type overload inherited from a base class always wins over a type overload inherited from a protocol.

@tayloraswift tayloraswift added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 15, 2023
@QuietMisdreavus QuietMisdreavus added the SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs. label Feb 16, 2023
@hborla hborla removed the triage needed This issue needs more specific labels label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.
Projects
None yet
Development

No branches or pull requests

3 participants