是否有可能获得要在宏中使用的方法调用的推断 return 类型?
Is it possible to get the inferred return type of a method call to be used in a macro?
如果未说明方法的 return 类型,是否仍然可以推断出要在宏中使用的 return 类型?
class Record
def explicit : String
"name"
end
def inferred
["a", "b"]
end
end
# The following works:
puts {{Record.methods.find { |m| m.name.id == "explicit".id }.return_type }}
# The following does not (because .return_type
# is useful when the method explicitly states the return type):
puts {{Record.methods.find { |m| m.name.id == "inferred".id }.return_type }}
不,宏 运行 在任何类型推断完成之前,不可能访问从宏推断的类型。这是因为在类型检查器可以正确推断 return 类型之前必须完全展开宏。
如果未说明方法的 return 类型,是否仍然可以推断出要在宏中使用的 return 类型?
class Record
def explicit : String
"name"
end
def inferred
["a", "b"]
end
end
# The following works:
puts {{Record.methods.find { |m| m.name.id == "explicit".id }.return_type }}
# The following does not (because .return_type
# is useful when the method explicitly states the return type):
puts {{Record.methods.find { |m| m.name.id == "inferred".id }.return_type }}
不,宏 运行 在任何类型推断完成之前,不可能访问从宏推断的类型。这是因为在类型检查器可以正确推断 return 类型之前必须完全展开宏。