Skip to content

Commit c7cbe62

Browse files
committed
Sema: Refactor resolveTopLevelIdentTypeComponent() a little
1 parent c4c5e9b commit c7cbe62

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,40 +1431,41 @@ static Type resolveTopLevelIdentTypeComponent(TypeResolution resolution,
14311431
return ErrorType::get(ctx);
14321432
}
14331433

1434-
// If we found nothing, complain and give ourselves a chance to recover.
1435-
if (current.isNull()) {
1436-
// Dynamic 'Self' in the result type of a function body.
1437-
if (id.isSimpleName(ctx.Id_Self)) {
1438-
if (auto *typeDC = DC->getInnermostTypeContext()) {
1439-
// FIXME: The passed-in TypeRepr should get 'typechecked' as well.
1440-
// The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl
1441-
// while the 'Self' type is more than just a reference to a TypeDecl.
1442-
auto selfType = resolution.mapTypeIntoContext(
1443-
typeDC->getSelfInterfaceType());
1444-
1445-
// Check if we can reference Self here, and if so, what kind of Self it is.
1446-
switch (getSelfTypeKind(DC, options)) {
1447-
case SelfTypeKind::StaticSelf:
1448-
return selfType;
1449-
case SelfTypeKind::DynamicSelf:
1450-
return DynamicSelfType::get(selfType, ctx);
1451-
case SelfTypeKind::InvalidSelf:
1452-
break;
1453-
}
1434+
// If we found a type declaration with the given name, return it now.
1435+
if (current) {
1436+
comp->setValue(currentDecl, currentDC);
1437+
return current;
1438+
}
1439+
1440+
// 'Self' inside of a nominal type refers to that type.
1441+
if (id.isSimpleName(ctx.Id_Self)) {
1442+
if (auto *typeDC = DC->getInnermostTypeContext()) {
1443+
// FIXME: The passed-in TypeRepr should get 'typechecked' as well.
1444+
// The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl
1445+
// while the 'Self' type is more than just a reference to a TypeDecl.
1446+
auto selfType = resolution.mapTypeIntoContext(
1447+
typeDC->getSelfInterfaceType());
1448+
1449+
// Check if we can reference 'Self' here, and if so, what kind of Self it is.
1450+
auto selfTypeKind = getSelfTypeKind(DC, options);
1451+
switch (selfTypeKind) {
1452+
case SelfTypeKind::StaticSelf:
1453+
return selfType;
1454+
case SelfTypeKind::DynamicSelf:
1455+
return DynamicSelfType::get(selfType, ctx);
1456+
case SelfTypeKind::InvalidSelf:
1457+
break;
14541458
}
14551459
}
1456-
1457-
// If we're not allowed to complain or we couldn't fix the
1458-
// source, bail out.
1459-
if (options.contains(TypeResolutionFlags::SilenceErrors))
1460-
return ErrorType::get(ctx);
1461-
1462-
return diagnoseUnknownType(resolution, nullptr, SourceRange(), comp,
1463-
lookupOptions);
14641460
}
14651461

1466-
comp->setValue(currentDecl, currentDC);
1467-
return current;
1462+
// If we're not allowed to complain, bail out.
1463+
if (options.contains(TypeResolutionFlags::SilenceErrors))
1464+
return ErrorType::get(ctx);
1465+
1466+
// Complain and give ourselves a chance to recover.
1467+
return diagnoseUnknownType(resolution, nullptr, SourceRange(), comp,
1468+
lookupOptions);
14681469
}
14691470

14701471
static void diagnoseAmbiguousMemberType(Type baseTy, SourceRange baseRange,

0 commit comments

Comments
 (0)