Skip to content

Commit ba7628c

Browse files
authored
Merge pull request #66898 from keith/ks/5.9-fix-missing-indexing-data-with-overloaded-type
[5.9] Fix missing indexing data with overloaded type
2 parents 0fe1f78 + 246d27e commit ba7628c

File tree

12 files changed

+153
-11
lines changed

12 files changed

+153
-11
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,33 @@ class FixedTypeRepr : public TypeRepr {
11741174
friend class TypeRepr;
11751175
};
11761176

1177+
/// A TypeRepr for uses of 'Self' in the type of a declaration.
1178+
class SelfTypeRepr : public TypeRepr {
1179+
Type Ty;
1180+
SourceLoc Loc;
1181+
1182+
public:
1183+
SelfTypeRepr(Type Ty, SourceLoc Loc)
1184+
: TypeRepr(TypeReprKind::Self), Ty(Ty), Loc(Loc) {}
1185+
1186+
/// Retrieve the location.
1187+
SourceLoc getLoc() const { return Loc; }
1188+
1189+
/// Retrieve the fixed type.
1190+
Type getType() const { return Ty; }
1191+
1192+
static bool classof(const TypeRepr *T) {
1193+
return T->getKind() == TypeReprKind::Self;
1194+
}
1195+
static bool classof(const SelfTypeRepr *T) { return true; }
1196+
1197+
private:
1198+
SourceLoc getStartLocImpl() const { return Loc; }
1199+
SourceLoc getEndLocImpl() const { return Loc; }
1200+
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
1201+
friend class TypeRepr;
1202+
};
1203+
11771204
class SILBoxTypeReprField {
11781205
SourceLoc VarOrLetLoc;
11791206
llvm::PointerIntPair<TypeRepr*, 1, bool> FieldTypeAndMutable;
@@ -1434,6 +1461,7 @@ inline bool TypeRepr::isSimple() const {
14341461
case TypeReprKind::Pack:
14351462
case TypeReprKind::Tuple:
14361463
case TypeReprKind::Fixed:
1464+
case TypeReprKind::Self:
14371465
case TypeReprKind::Array:
14381466
case TypeReprKind::SILBox:
14391467
case TypeReprKind::Isolated:

include/swift/AST/TypeReprNodes.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ ABSTRACT_TYPEREPR(Specifier, TypeRepr)
7474
SPECIFIER_TYPEREPR(CompileTimeConst, SpecifierTypeRepr)
7575
TYPEREPR(Fixed, TypeRepr)
7676
TYPEREPR(SILBox, TypeRepr)
77-
LAST_TYPEREPR(SILBox)
77+
TYPEREPR(Self, TypeRepr)
78+
LAST_TYPEREPR(Self)
7879

7980
#undef SPECIFIER_TYPEREPR
8081
#undef ABSTRACT_TYPEREPR

lib/AST/ASTDumper.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,22 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr> {
33413341
PrintWithColorRAII(OS, ParenthesisColor) << ')';
33423342
}
33433343

3344+
void visitSelfTypeRepr(SelfTypeRepr *T) {
3345+
printCommon("type_self");
3346+
auto Ty = T->getType();
3347+
if (Ty) {
3348+
auto &srcMgr = Ty->getASTContext().SourceMgr;
3349+
if (T->getLoc().isValid()) {
3350+
OS << " location=@";
3351+
T->getLoc().print(OS, srcMgr);
3352+
} else {
3353+
OS << " location=<<invalid>>";
3354+
}
3355+
}
3356+
OS << " type="; Ty.dump(OS);
3357+
PrintWithColorRAII(OS, ParenthesisColor) << ')';
3358+
}
3359+
33443360
void visitSILBoxTypeRepr(SILBoxTypeRepr *T) {
33453361
printCommon("sil_box");
33463362
Indent += 2;

lib/AST/ASTWalker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,10 @@ bool Traversal::visitFixedTypeRepr(FixedTypeRepr *T) {
21932193
return false;
21942194
}
21952195

2196+
bool Traversal::visitSelfTypeRepr(SelfTypeRepr *T) {
2197+
return false;
2198+
}
2199+
21962200
bool Traversal::visitSILBoxTypeRepr(SILBoxTypeRepr *T) {
21972201
for (auto &field : T->getFields()) {
21982202
if (doIt(field.getFieldType()))

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
30003000

30013001
case TypeReprKind::Fixed:
30023002
llvm_unreachable("Cannot get fixed TypeReprs in name lookup");
3003+
case TypeReprKind::Self:
3004+
llvm_unreachable("Cannot get fixed SelfTypeRepr in name lookup");
30033005

30043006
case TypeReprKind::Optional:
30053007
case TypeReprKind::ImplicitlyUnwrappedOptional:

lib/AST/TypeRepr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ void FixedTypeRepr::printImpl(ASTPrinter &Printer,
629629
getType().print(Printer, Opts);
630630
}
631631

632+
void SelfTypeRepr::printImpl(ASTPrinter &Printer,
633+
const PrintOptions &Opts) const {
634+
getType().print(Printer, Opts);
635+
}
636+
632637
void SILBoxTypeRepr::printImpl(ASTPrinter &Printer,
633638
const PrintOptions &Opts) const {
634639
// TODO

lib/IDE/SourceEntityWalker.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,23 @@ ASTWalker::PreWalkAction SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
651651
return Action::StopIf(!Continue);
652652
}
653653
} else if (auto FT = dyn_cast<FixedTypeRepr>(T)) {
654-
ValueDecl *VD = FT->getType()->getAnyGeneric();
655-
if (auto DT = FT->getType()->getAs<DynamicSelfType>())
654+
if (ValueDecl *VD = FT->getType()->getAnyGeneric()) {
655+
auto Data = ReferenceMetaData(SemaReferenceKind::TypeRef, None);
656+
Data.isImplicitCtorType = true;
657+
auto Continue = passReference(VD, FT->getType(), FT->getLoc(),
658+
FT->getSourceRange(), Data);
659+
return Action::StopIf(!Continue);
660+
}
661+
} else if (auto ST = dyn_cast<SelfTypeRepr>(T)) {
662+
ValueDecl *VD = ST->getType()->getAnyGeneric();
663+
if (auto DT = ST->getType()->getAs<DynamicSelfType>())
656664
VD = DT->getSelfType()->getAnyGeneric();
657665

658666
if (VD) {
659667
auto Data = ReferenceMetaData(SemaReferenceKind::TypeRef, llvm::None);
660668
Data.isImplicitCtorType = true;
661-
auto Continue = passReference(VD, FT->getType(), FT->getLoc(),
662-
FT->getSourceRange(), Data);
669+
auto Continue = passReference(VD, ST->getType(), ST->getLoc(),
670+
ST->getSourceRange(), Data);
663671
return Action::StopIf(!Continue);
664672
}
665673
}

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ class ChildIndexFinder : public TypeReprVisitor<ChildIndexFinder, FoundResult> {
220220
FoundResult visitFixedTypeRepr(FixedTypeRepr *T) {
221221
return handleParent(T, ArrayRef<TypeRepr*>());
222222
}
223+
224+
FoundResult visitSelfTypeRepr(SelfTypeRepr *T) {
225+
return handleParent(T, ArrayRef<TypeRepr*>());
226+
}
223227
};
224228

225229
struct ConversionFunctionInfo {

lib/Sema/CSApply.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,19 @@ namespace {
624624
locator, implicit, semantics);
625625
}
626626

627-
if (isa<TypeDecl>(decl) && !isa<ModuleDecl>(decl)) {
628-
auto typeExpr = TypeExpr::createImplicitHack(
629-
loc.getBaseNameLoc(), adjustedFullType->getMetatypeInstanceType(), ctx);
630-
cs.cacheType(typeExpr);
631-
return typeExpr;
627+
if (auto *typeDecl = dyn_cast<TypeDecl>(decl)) {
628+
if (!isa<ModuleDecl>(decl)) {
629+
TypeExpr *typeExpr = nullptr;
630+
if (implicit) {
631+
typeExpr = TypeExpr::createImplicitHack(
632+
loc.getBaseNameLoc(), adjustedFullType->getMetatypeInstanceType(), ctx);
633+
} else {
634+
typeExpr = TypeExpr::createForDecl(loc, typeDecl, dc);
635+
typeExpr->setType(adjustedFullType);
636+
}
637+
cs.cacheType(typeExpr);
638+
return typeExpr;
639+
}
632640
}
633641

634642
auto ref = resolveConcreteDeclRef(decl, locator);

lib/Sema/PreCheckExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
597597
if (typeContext->getSelfClassDecl())
598598
SelfType = DynamicSelfType::get(SelfType, Context);
599599
return new (Context)
600-
TypeExpr(new (Context) FixedTypeRepr(SelfType, Loc));
600+
TypeExpr(new (Context) SelfTypeRepr(SelfType, Loc));
601601
}
602602
}
603603

0 commit comments

Comments
 (0)