@@ -1435,40 +1435,41 @@ static Type resolveTopLevelIdentTypeComponent(TypeResolution resolution,
14351435 return ErrorType::get (ctx);
14361436 }
14371437
1438- // If we found nothing, complain and give ourselves a chance to recover.
1439- if (current.isNull ()) {
1440- // Dynamic 'Self' in the result type of a function body.
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- switch (getSelfTypeKind (DC, options)) {
1451- case SelfTypeKind::StaticSelf:
1452- return selfType;
1453- case SelfTypeKind::DynamicSelf:
1454- return DynamicSelfType::get (selfType, ctx);
1455- case SelfTypeKind::InvalidSelf:
1456- break ;
1457- }
1438+ // If we found a type declaration with the given name, return it now.
1439+ if (current) {
1440+ comp->setValue (currentDecl, currentDC);
1441+ return current;
1442+ }
1443+
1444+ // 'Self' inside of a nominal type refers to that type.
1445+ if (id.isSimpleName (ctx.Id_Self )) {
1446+ if (auto *typeDC = DC->getInnermostTypeContext ()) {
1447+ // FIXME: The passed-in TypeRepr should get 'typechecked' as well.
1448+ // The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl
1449+ // while the 'Self' type is more than just a reference to a TypeDecl.
1450+ auto selfType = resolution.mapTypeIntoContext (
1451+ typeDC->getSelfInterfaceType ());
1452+
1453+ // Check if we can reference 'Self' here, and if so, what kind of Self it is.
1454+ auto selfTypeKind = getSelfTypeKind (DC, options);
1455+ switch (selfTypeKind) {
1456+ case SelfTypeKind::StaticSelf:
1457+ return selfType;
1458+ case SelfTypeKind::DynamicSelf:
1459+ return DynamicSelfType::get (selfType, ctx);
1460+ case SelfTypeKind::InvalidSelf:
1461+ break ;
14581462 }
14591463 }
1460-
1461- // If we're not allowed to complain or we couldn't fix the
1462- // source, bail out.
1463- if (options.contains (TypeResolutionFlags::SilenceErrors))
1464- return ErrorType::get (ctx);
1465-
1466- return diagnoseUnknownType (resolution, nullptr , SourceRange (), comp,
1467- lookupOptions);
14681464 }
14691465
1470- comp->setValue (currentDecl, currentDC);
1471- return current;
1466+ // If we're not allowed to complain, bail out.
1467+ if (options.contains (TypeResolutionFlags::SilenceErrors))
1468+ return ErrorType::get (ctx);
1469+
1470+ // Complain and give ourselves a chance to recover.
1471+ return diagnoseUnknownType (resolution, nullptr , SourceRange (), comp,
1472+ lookupOptions);
14721473}
14731474
14741475static void diagnoseAmbiguousMemberType (Type baseTy, SourceRange baseRange,
0 commit comments