Skip to content

Revert "SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations" #2477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ Swift 3.0
`NS[Mutable]Dictionary` are still imported as nongeneric classes for
the time being.

* [SE-0036](https://github.com/apple/swift-evolution/blob/master/proposals/0036-enum-dot.md):
Enum elements can no longer be accessed like instance members in instance methods.
* As part of the changes for SE-0055 (see below), the *pointee* types of
imported pointers (e.g. the `id` in `id *`) are no longer assumed to always
be `_Nullable` even if annotated otherwise. However, an implicit or explicit
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ ERROR(could_not_use_type_member,none,
ERROR(could_not_use_type_member_on_instance,none,
"static member %1 cannot be used on instance of type %0",
(Type, DeclName))
ERROR(could_not_use_enum_element_on_instance,none,
"enum element %0 cannot be referenced as an instance member",
(DeclName))
ERROR(could_not_use_type_member_on_existential,none,
"static member %1 cannot be used on protocol metatype %0",
(Type, DeclName))
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
OS << '\n';
printRec(E->getArgument());
}
OS << ")";
OS << "')";
}
void visitDotSelfExpr(DotSelfExpr *E) {
printCommon(E, "dot_self_expr");
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
if (FD->isStatic() && !isMetatypeType)
continue;
} else if (isa<EnumElementDecl>(Result)) {
Results.push_back(UnqualifiedLookupResult(BaseDecl, Result));
Results.push_back(UnqualifiedLookupResult(MetaBaseDecl, Result));
continue;
}

Expand Down
16 changes: 0 additions & 16 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2278,22 +2278,6 @@ diagnoseUnviableLookupResults(MemberLookupResult &result, Type baseObjTy,
} else {
// Otherwise the static member lookup was invalid because it was
// called on an instance

// Handle enum element lookup on instance type
auto lookThroughBaseObjTy = baseObjTy->lookThroughAllAnyOptionalTypes();
if (lookThroughBaseObjTy->is<EnumType>()
|| lookThroughBaseObjTy->is<BoundGenericEnumType>()) {
for (auto cand : result.UnviableCandidates) {
ValueDecl *decl = cand.first;
if (isa<EnumElementDecl>(decl)) {
diagnose(loc, diag::could_not_use_enum_element_on_instance,
memberName);
return;
}
}
}

// Provide diagnostic other static member lookups on instance type
diagnose(loc, diag::could_not_use_type_member_on_instance,
baseObjTy, memberName)
.highlight(baseRange).highlight(nameLoc.getSourceRange());
Expand Down
7 changes: 1 addition & 6 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,11 @@ filterForEnumElement(LookupResult foundElements) {
EnumElementDecl *foundElement = nullptr;
VarDecl *foundConstant = nullptr;

for (swift::LookupResult::Result result : foundElements) {
ValueDecl *e = result.Decl;
for (ValueDecl *e : foundElements) {
assert(e);
if (e->isInvalid()) {
continue;
}
// Skip if the enum element was referenced as an instance member
if (!result.Base || !result.Base->getType()->is<MetatypeType>()) {
continue;
}

if (auto *oe = dyn_cast<EnumElementDecl>(e)) {
// Ambiguities should be ruled out by parsing.
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
template<typename StmtTy>
bool typeCheckStmt(StmtTy *&S) {
StmtTy *S2 = cast_or_null<StmtTy>(visit(S));
if (S2 == nullptr) return true;
if (S2 == 0) return true;
S = S2;
performStmtDiagnostics(TC, S);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ internal enum _CollectionOperation : Equatable {
var newElementsIds = elementsLastMutatedStateIds
var newEndIndexId = endIndexLastMutatedStateId
switch self {
case .reserveCapacity:
case reserveCapacity:
let invalidIndices = newElementsIds.indices
newElementsIds.replaceSubrange(
Range(invalidIndices),
with: repeatElement(nextStateId, count: invalidIndices.count))
newEndIndexId = nextStateId

case .append:
case append:
newElementsIds.append(nextStateId)
newEndIndexId = nextStateId

case .appendContentsOf(let count):
case appendContentsOf(let count):
newElementsIds.append(contentsOf:
repeatElement(nextStateId, count: count))
newEndIndexId = nextStateId

case .replaceRange(let subRange, let replacementCount):
case replaceRange(let subRange, let replacementCount):
newElementsIds.replaceSubrange(
subRange,
with: repeatElement(nextStateId, count: replacementCount))
Expand All @@ -185,7 +185,7 @@ internal enum _CollectionOperation : Equatable {
with: repeatElement(nextStateId, count: invalidIndices.count))
newEndIndexId = nextStateId

case .insert(let atIndex):
case insert(let atIndex):
newElementsIds.insert(nextStateId, at: atIndex)

let invalidIndices = atIndex..<newElementsIds.endIndex
Expand All @@ -194,7 +194,7 @@ internal enum _CollectionOperation : Equatable {
with: repeatElement(nextStateId, count: invalidIndices.count))
newEndIndexId = nextStateId

case .insertContentsOf(let atIndex, let count):
case insertContentsOf(let atIndex, let count):
newElementsIds.insert(
contentsOf: repeatElement(nextStateId, count: count),
at: atIndex)
Expand All @@ -205,7 +205,7 @@ internal enum _CollectionOperation : Equatable {
with: repeatElement(nextStateId, count: invalidIndices.count))
newEndIndexId = nextStateId

case .removeAtIndex(let index):
case removeAtIndex(let index):
newElementsIds.remove(at: index)

let invalidIndices = index..<newElementsIds.endIndex
Expand All @@ -214,11 +214,11 @@ internal enum _CollectionOperation : Equatable {
with: repeatElement(nextStateId, count: invalidIndices.count))
newEndIndexId = nextStateId

case .removeLast:
case removeLast:
newElementsIds.removeLast()
newEndIndexId = nextStateId

case .removeRange(let subRange):
case removeRange(let subRange):
newElementsIds.removeSubrange(subRange)

let invalidIndices = subRange.lowerBound..<newElementsIds.endIndex
Expand All @@ -227,7 +227,7 @@ internal enum _CollectionOperation : Equatable {
with: repeatElement(nextStateId, count: invalidIndices.count))
newEndIndexId = nextStateId

case .removeAll(let keepCapacity):
case removeAll(let keepCapacity):
newElementsIds.removeAll(keepingCapacity: keepCapacity)
newEndIndexId = nextStateId
}
Expand Down
Loading