How to extract return type of a class member method ValueDecl?

I'm playing around with the compiler and I have a ValueDecl whose Type that evaluates to (Square) -> () -> Double when using getInterfaceType(). How do I get Double from that example?

You could try this

if(auto fnTy = declVar->getInterfaceType()->getAs<AnyFunctionType>()) {
  if (auto resultFnTy = fnTy->getResult()->getAs<AnyFunctionType>()) { // Get result () -> Double as FunctionType
    auto result = resultFnTy->getResult() // Double
  }
}
1 Like

If the valueDecl is a FuncDecl, you can also call getResultInterfaceType() to directly get Double there.

1 Like

Thank you! It's perfect :)