Skip to content

Commit 15dc2e9

Browse files
committed
[ASTGen] Handle the 'Any' type
1 parent 5870421 commit 15dc2e9

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ void *MemberTypeRepr_create(void *ctx, void *baseComponent,
282282
void *GenericIdentTypeRepr_create(void *ctx, BridgedIdentifier name,
283283
void *nameLoc, BridgedArrayRef genericArgs,
284284
void *lAngle, void *rAngle);
285+
void *EmptyCompositionTypeRepr_create(void *ctx, void *anyLoc);
285286
void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef types,
286287
void *firstTypeLoc);
287288
void *FunctionTypeRepr_create(void *ctx, void *argsTy, void *_Nullable asyncLoc,

lib/AST/CASTBridging.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ void *MemberTypeRepr_create(void *ctx, void *baseComponent,
542542
memberComponents);
543543
}
544544

545+
void *EmptyCompositionTypeRepr_create(void *ctx, void *anyLocPtr) {
546+
ASTContext &Context = *static_cast<ASTContext *>(ctx);
547+
SourceLoc anyLoc = getSourceLocFromPointer(anyLocPtr);
548+
return CompositionTypeRepr::createEmptyComposition(Context, anyLoc);
549+
}
550+
545551
void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef types,
546552
void *firstTypeLoc) {
547553
ASTContext &Context = *static_cast<ASTContext *>(ctx);

lib/ASTGen/Sources/ASTGen/Types.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ extension ASTGenVisitor {
66
public func visit(_ node: SimpleTypeIdentifierSyntax) -> ASTNode {
77
let loc = self.base.advanced(by: node.position.utf8Offset).raw
88

9+
// If this is the bare 'Any' keyword, produce an empty composition type.
10+
if node.name.tokenKind == .keyword(.Any) && node.genericArgumentClause == nil {
11+
return .type(EmptyCompositionTypeRepr_create(self.ctx, loc))
12+
}
13+
914
var text = node.name.text
1015
let id = text.withUTF8 { buf in
1116
return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count)

test/ASTGen/verify-parse.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ func test7(_ b: inout Bool) {
4545

4646
func test8(_ i: _const Int) {
4747
}
48+
49+
func test9(_ value: Any) { }

0 commit comments

Comments
 (0)