Skip to content

Commit 310be1b

Browse files
committed
-
1 parent 3e565d4 commit 310be1b

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Sources/PrincipleMacros/Syntax/Extensions/ClassDeclSyntax.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ extension ClassDeclSyntax {
1818
let visitor = SubclassKeywordsVisitor(for: self)
1919
return visitor.verifiedSuperclass()
2020
}
21+
22+
public func inferredSuperclass(
23+
expectation: Bool?
24+
) throws -> TypeSyntax? {
25+
switch expectation {
26+
case true:
27+
if let superclass = unverifiedInferredSuperclass {
28+
return superclass
29+
}
30+
throw DiagnosticsError(
31+
node: self,
32+
message: "\(name.trimmed) should have a superclass"
33+
)
34+
case false:
35+
return nil
36+
case nil:
37+
return inferredSuperclass()
38+
}
39+
}
2140
}
2241

2342
extension ClassDeclSyntax {

0 commit comments

Comments
 (0)