Skip to content

Commit 6577e68

Browse files
author
David Ungar
committed
Fixes for review
1 parent 3c7de8d commit 6577e68

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,8 +2919,8 @@ class TypeAliasDecl : public GenericTypeDecl {
29192919
/// The location of the equal '=' token
29202920
SourceLoc EqualLoc;
29212921

2922-
/// The end of the type
2923-
SourceLoc EndLoc;
2922+
/// The end of the type, valid even when the type cannot be parsed
2923+
SourceLoc TypeEndLoc;
29242924

29252925
/// The location of the right-hand side of the typealias binding
29262926
TypeLoc UnderlyingTy;
@@ -2938,7 +2938,7 @@ class TypeAliasDecl : public GenericTypeDecl {
29382938
return EqualLoc;
29392939
}
29402940

2941-
void setEndLoc(SourceLoc e) { EndLoc = e; }
2941+
void setTypeEndLoc(SourceLoc e) { TypeEndLoc = e; }
29422942

29432943
TypeLoc &getUnderlyingTypeLoc() {
29442944
return UnderlyingTy;

lib/AST/Decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3503,7 +3503,9 @@ SourceRange TypeAliasDecl::getSourceRange() const {
35033503
return { TypeAliasLoc, TrailingWhereClauseSourceRange.End };
35043504
if (UnderlyingTy.hasLocation())
35053505
return { TypeAliasLoc, UnderlyingTy.getSourceRange().End };
3506-
return {TypeAliasLoc, EndLoc};
3506+
if (TypeEndLoc.isValid())
3507+
return { TypeAliasLoc, TypeEndLoc };
3508+
return { TypeAliasLoc, getNameLoc() };
35073509
}
35083510

35093511
void TypeAliasDecl::setUnderlyingType(Type underlying) {

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,7 +4098,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
40984098
}
40994099

41004100
UnderlyingTy = parseType(diag::expected_type_in_typealias);
4101-
TAD->setEndLoc(getEndOfPreviousLoc());
4101+
TAD->setTypeEndLoc(PreviousLoc);
41024102
Status |= UnderlyingTy;
41034103
}
41044104

@@ -6394,7 +6394,6 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
63946394
SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion();
63956395
if (whereStatus.hasCodeCompletion() && !CodeCompletion) {
63966396
// Trigger delayed parsing, no need to continue.
6397-
Subscript->setEndLoc(getEndOfPreviousLoc().getAdvancedLoc(-1));
63986397
return whereStatus;
63996398
}
64006399
}
@@ -6429,6 +6428,9 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
64296428
accessors, Subscript, StaticLoc);
64306429
}
64316430

6431+
// Now that it's been parsed, set the end location.
6432+
Subscript->setEndLoc(PreviousLoc);
6433+
64326434
bool Invalid = false;
64336435
// Reject 'subscript' functions outside of type decls
64346436
if (!(Flags & PD_HasContainerType)) {
@@ -6438,8 +6440,6 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
64386440

64396441
accessors.record(*this, Subscript, (Invalid || !Status.isSuccess()), Decls);
64406442

6441-
Subscript->setEndLoc(getEndOfPreviousLoc().getAdvancedLoc(-1));
6442-
64436443
// No need to setLocalDiscriminator because subscripts cannot
64446444
// validly appear outside of type decls.
64456445
return makeParserResult(Status, Subscript);

0 commit comments

Comments
 (0)