@@ -1431,40 +1431,41 @@ static Type resolveTopLevelIdentTypeComponent(TypeResolution resolution,
1431
1431
return ErrorType::get (ctx);
1432
1432
}
1433
1433
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 ;
1454
1458
}
1455
1459
}
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);
1464
1460
}
1465
1461
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);
1468
1469
}
1469
1470
1470
1471
static void diagnoseAmbiguousMemberType (Type baseTy, SourceRange baseRange,
0 commit comments