Skip to content

Commit deecb58

Browse files
author
Nathan Hawes
committed
[IDE] Loosen assertion check in IDE/SyntaxModelWalker
We were asserting that the attribute range recorded in the AST started at the same location as the fist unconsumed SyntaxNode in the file. This should be true in most cases, but isn't for mispelled attributes, corrected in the AST but not recognised or present in the list of SyntaxNodes. E.g. @Availability(...) comes through as if @available(...) was specified, but there's no SyntaxNode for it because we don't highlight invalid attributes (to indicate they're invalid). Resolves rdar://problem/62201594 Resolves https://bugs.swift.org/browse/SR-12500
1 parent 5239668 commit deecb58

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/IDE/SyntaxModel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,13 @@ bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D,
12141214
if (!passNode({SyntaxNodeKind::AttributeBuiltin, Next.Range}))
12151215
return false;
12161216
} else {
1217-
assert(0 && "Attribute's TokenNodes already consumed?");
1217+
// Only mispelled attributes, corrected in the AST but not
1218+
// recognised or present in TokenNodes should get us here.
1219+
// E.g. @availability(...) comes through as if @available(...) was
1220+
// specified, but there's no TokenNode because we don't highlight them
1221+
// (to indicate they're invalid).
1222+
assert(Next.Range.getStart() == D->getRange().Start &&
1223+
"Attribute's TokenNodes already consumed?");
12181224
}
12191225
} else {
12201226
assert(0 && "No TokenNodes?");

test/IDE/coloring.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,8 @@ struct FreeWhere<T> {
554554
// CHECK: <kw>typealias</kw> Alias = <type>Int</type> <kw>where</kw> <type>T</type> == <type>Int</type>
555555
typealias Alias = Int where T == Int
556556
}
557+
558+
// Renamed attribute ('fixed' to @available by the parser after emitting an error, so not treated as a custom attribute)
559+
// CHECK: @availability(<kw>macOS</kw> <float>10.11</float>, *)
560+
@availability(macOS 10.11, *)
561+
class HasMisspelledAttr {}

0 commit comments

Comments
 (0)