Skip to content

Commit 9481e86

Browse files
committed
[IDE] Make isDynamicRef take a getType function
This allows isDynamicRef to work with types from a constraint system solution
1 parent 1fb4393 commit 9481e86

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

include/swift/IDE/Utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/DeclNameLoc.h"
1919
#include "swift/AST/Effects.h"
2020
#include "swift/AST/Module.h"
21+
#include "swift/AST/Expr.h"
2122
#include "swift/Basic/LLVM.h"
2223
#include "swift/IDE/SourceEntityWalker.h"
2324
#include "swift/Parse/Token.h"
@@ -740,7 +741,7 @@ bool isDeclOverridable(ValueDecl *D);
740741
/// one in `SomeType`. Contrast that to `type(of: foo).classMethod()` where
741742
/// `classMethod` could be any `classMethod` up or down the hierarchy from the
742743
/// type of the \p Base expression.
743-
bool isDynamicRef(Expr *Base, ValueDecl *D);
744+
bool isDynamicRef(Expr *Base, ValueDecl *D, llvm::function_ref<Type(Expr *)> getType = [](Expr *E) { return E->getType(); });
744745

745746
/// Adds the resolved nominal types of \p Base to \p Types.
746747
void getReceiverType(Expr *Base,

lib/IDE/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ bool swift::ide::isDeclOverridable(ValueDecl *D) {
921921
return true;
922922
}
923923

924-
bool swift::ide::isDynamicRef(Expr *Base, ValueDecl *D) {
924+
bool swift::ide::isDynamicRef(Expr *Base, ValueDecl *D, llvm::function_ref<Type(Expr *)> getType) {
925925
if (!isDeclOverridable(D))
926926
return false;
927927

@@ -940,7 +940,7 @@ bool swift::ide::isDynamicRef(Expr *Base, ValueDecl *D) {
940940

941941
// `type(of: foo).staticOrClassMethod()`. A static method may be "dynamic"
942942
// here, but not if the instance type is a struct/enum.
943-
if (auto IT = Base->getType()->getAs<MetatypeType>()) {
943+
if (auto IT = getType(Base)->getAs<MetatypeType>()) {
944944
auto InstanceType = IT->getInstanceType();
945945
if (InstanceType->getStructOrBoundGenericStruct() ||
946946
InstanceType->getEnumOrBoundGenericEnum())

0 commit comments

Comments
 (0)