Hint at how to get properties of inherited Type?

I'm playing around with the compiler, trying to implement a simple feature ([SR-15176] Fixit for `override func` that should be `override var` · Issue #57499 · apple/swift · GitHub).

So I have a FuncDecl, FD, that is trying to override a method from its superclass.

FD->getOverriddenDecl() returns a nullptr so there's no method with the same signature in the superclass.

I'd like to check if at least there's a property with the same name in the superclass, and eventually get its Type.

With FD->getDeclContext()->getSelfClassDecl()->getInherited().front().getType() I see the inherited class name, but I'm having a hard time figuring out how to explore that class (or, I should say, Type) properties.

Any hint?

There are some things to think about here:

  • The member property may be in a super class of the super class in many levels of hierarchy.
class A {
  var a: Int { 0 }
class B: A {}
class C: B {
  override var a: Int { 1 }
  • I think the operation we want to do here is a nameLookup(which by definition is that by name find a declaration associated with it in a given context) in the immediate super class. Search for performMemberLookup usages in the code base and you will be able to see how is used, but IIUC the idea is essentially we have the name of the function, so we perform a name lookup on superclass trying of a member computed property with that name and if that given declaration produces the same type.

Hope that helps =]

Ah for the first point, I think name lookup will look for the member in levels of hierarchy so that will not be a problem, but not sure. That will be a good test case to add as well

Thank you, Luciano! That's exactly what I needed, I managed to successfully perform a lookup

1 Like