Skip to content

Commit

Permalink
Tidy up comments and final testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Apr 11, 2019
1 parent afba3d4 commit 7ae55d3
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,12 @@ static std::string getDeclNameFromContext(DeclContext *dc,
}
}

static Type isSE0068(TypeResolution resolution, TypeResolutionOptions options) {
//
// SE-0068 is "Expanding Swift Self to class members and value types"
// https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md
//
static Type SelfAllowedBySE0068(TypeResolution resolution,
TypeResolutionOptions options) {
auto dc = resolution.getDeclContext();
ASTContext &ctx = dc->getASTContext();
DeclContext *nominalDC = nullptr;
Expand All @@ -1044,24 +1049,13 @@ static Type isSE0068(TypeResolution resolution, TypeResolutionOptions options) {
bool insideClass = nominalDC->getSelfClassDecl() != nullptr;
AbstractFunctionDecl *methodDecl = dc->getInnermostMethodContext();
bool declaringMethod = methodDecl &&
methodDecl->getDeclContext() == dc->getParentForLookup();
methodDecl->getDeclContext() == dc->getParentForLookup();
bool isMutablePropertyOrSubscriptOfClass = insideClass &&
(options.is(TypeResolverContext::PatternBindingDecl) ||
options.is(TypeResolverContext::FunctionResult));
bool isTypeAliasInClass = insideClass &&
options.is(TypeResolverContext::TypeAliasDecl);

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

// 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.

// if (isMutablePropertyOrSubscriptOfClass) {
// if (auto prop = dyn_cast_or_null<ValueDecl>
// (dc->getInnermostDeclarationDeclContext()))
// if (!prop->isSettable(dc))
// isMutablePropertyOrSubscriptOfClass = false;
// }

if (((!insideClass || !declaringMethod) &&
!isMutablePropertyOrSubscriptOfClass && !isTypeAliasInClass &&
!options.is(TypeResolverContext::GenericRequirement)) ||
Expand Down Expand Up @@ -1370,7 +1364,7 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution,
return ErrorType::get(ctx);

if (id == ctx.Id_Self)
if (auto SelfType = isSE0068(resolution, options))
if (auto SelfType = SelfAllowedBySE0068(resolution, options))
return SelfType;

return diagnoseUnknownType(resolution, nullptr, SourceRange(), comp,
Expand Down

0 comments on commit 7ae55d3

Please sign in to comment.