Skip to content

Commit 2614c9b

Browse files
committed
[ASTGen] The 'extendedType' argument for attached macros does not have a
source location. (cherry picked from commit 43e2026)
1 parent 89732fc commit 2614c9b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/ASTGen/Sources/ASTGen/Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ func expandAttachedMacroIPC(
819819
let extendedTypeSyntax: PluginMessage.Syntax?
820820
if (!qualifiedType.isEmpty) {
821821
let typeSyntax: TypeSyntax = "\(raw: qualifiedType)"
822-
extendedTypeSyntax = .init(syntax: Syntax(typeSyntax), in: parentDeclSourceFilePtr!)!
822+
extendedTypeSyntax = .init(syntax: Syntax(typeSyntax))!
823823
} else {
824824
extendedTypeSyntax = nil
825825
}

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,31 @@ extension PluginMessage.Syntax {
397397
line: loc.line,
398398
column: loc.column))
399399
}
400+
401+
init?(syntax: Syntax) {
402+
let kind: PluginMessage.Syntax.Kind
403+
switch true {
404+
case syntax.is(DeclSyntax.self): kind = .declaration
405+
case syntax.is(ExprSyntax.self): kind = .expression
406+
case syntax.is(StmtSyntax.self): kind = .statement
407+
case syntax.is(TypeSyntax.self): kind = .type
408+
case syntax.is(PatternSyntax.self): kind = .pattern
409+
case syntax.is(AttributeSyntax.self): kind = .attribute
410+
default: return nil
411+
}
412+
413+
let source = syntax.description
414+
415+
self.init(
416+
kind: kind,
417+
source: source,
418+
location: .init(
419+
fileID: "",
420+
fileName: "",
421+
offset: 0,
422+
line: 0,
423+
column: 0
424+
)
425+
)
426+
}
400427
}

0 commit comments

Comments
 (0)