Skip to content

Commit afba3d4

Browse files
committed
Move off diagnostic path
1 parent 8b64cd4 commit afba3d4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,8 @@ static Type isSE0068(TypeResolution resolution, TypeResolutionOptions options) {
10531053

10541054
// printf("%d\n", options.getBaseContext());
10551055

1056+
// Causes: Assertion failed: (hasSelfMetadataParam() && "This method can only be called if the " "SILFunction has a self-metadata parameter"), function getSelfMetadataArgument, file /Volumes/Elements/swift-self/swift/include/swift/SIL/SILFunction.h, line 955.
1057+
10561058
// if (isMutablePropertyOrSubscriptOfClass) {
10571059
// if (auto prop = dyn_cast_or_null<ValueDecl>
10581060
// (dc->getInnermostDeclarationDeclContext()))
@@ -1099,12 +1101,10 @@ static Type diagnoseUnknownType(TypeResolution resolution,
10991101
NominalTypeDecl *nominal = nullptr;
11001102
if ((nominalDC = dc->getInnermostTypeContext()) &&
11011103
(nominal = nominalDC->getSelfNominalTypeDecl())) {
1104+
// Attempt to refer to 'Self' within a non-protocol nominal
1105+
// type. Fix this by replacing 'Self' with the nominal type name.
11021106
assert(!isa<ProtocolDecl>(nominal) && "Cannot be a protocol");
11031107

1104-
if (auto SelfType = isSE0068(resolution, options))
1105-
return SelfType;
1106-
1107-
// Attempt to refer to 'Self' within a non-protocol nominal type.
11081108
// Produce a Fix-It replacing 'Self' with the nominal type name.
11091109
auto name = getDeclNameFromContext(dc, nominal);
11101110
diags.diagnose(comp->getIdLoc(), diag::self_in_nominal, name)
@@ -1285,21 +1285,18 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution,
12851285
DeclContext *lookupDC = DC;
12861286

12871287
// Dynamic 'Self' in the result type of a function body.
1288-
if (comp->getIdentifier() == ctx.Id_Self) {
1289-
if (options.getBaseContext() == TypeResolverContext::DynamicSelfResult) {
1290-
auto func = cast<FuncDecl>(DC);
1291-
assert(func->hasDynamicSelf() && "Not marked as having dynamic Self?");
1288+
if (options.getBaseContext() == TypeResolverContext::DynamicSelfResult &&
1289+
comp->getIdentifier() == ctx.Id_Self) {
1290+
auto func = cast<FuncDecl>(DC);
1291+
assert(func->hasDynamicSelf() && "Not marked as having dynamic Self?");
12921292

1293-
// FIXME: The passed-in TypeRepr should get 'typechecked' as well.
1294-
// The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl
1295-
// while the 'Self' type is more than just a reference to a TypeDecl.
1293+
// FIXME: The passed-in TypeRepr should get 'typechecked' as well.
1294+
// The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl
1295+
// while the 'Self' type is more than just a reference to a TypeDecl.
12961296

1297-
auto selfType = resolution.mapTypeIntoContext(
1298-
func->getDeclContext()->getSelfInterfaceType());
1299-
return DynamicSelfType::get(selfType, ctx);
1300-
}
1301-
// if (auto SelfType = isSE0068(resolution, options))
1302-
// return SelfType;
1297+
auto selfType = resolution.mapTypeIntoContext(
1298+
func->getDeclContext()->getSelfInterfaceType());
1299+
return DynamicSelfType::get(selfType, ctx);
13031300
}
13041301

13051302
auto id = comp->getIdentifier();
@@ -1372,6 +1369,10 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution,
13721369
if (options.contains(TypeResolutionFlags::SilenceErrors))
13731370
return ErrorType::get(ctx);
13741371

1372+
if (id == ctx.Id_Self)
1373+
if (auto SelfType = isSE0068(resolution, options))
1374+
return SelfType;
1375+
13751376
return diagnoseUnknownType(resolution, nullptr, SourceRange(), comp,
13761377
options, lookupOptions);
13771378
}

0 commit comments

Comments
 (0)