-
Notifications
You must be signed in to change notification settings - Fork 440
Don’t automaticaly conform all decl/stmt/etc. nodes to ExpressibleByStringLiteral
#1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don’t automaticaly conform all decl/stmt/etc. nodes to ExpressibleByStringLiteral
#1269
Conversation
@swift-ci Please test |
2d43d17
to
032ebda
Compare
public extension HasTrailingCodeBlock where Self: StmtSyntaxProtocol { | ||
init(_ signature: PartialSyntaxNodeString, @CodeBlockItemListBuilder bodyBuilder: () -> CodeBlockItemListSyntax) throws { | ||
let stmt = StmtSyntax("\(signature) {}") | ||
guard let castedStmt = stmt.as(Self.self) else { | ||
throw SyntaxStringInterpolationError.producedInvalidNodeType(expectedType: IfStmtSyntax.self, actualNode: stmt) | ||
} | ||
self = castedStmt | ||
self.body = CodeBlockSyntax(statements: bodyBuilder()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not a huge fan of this one, but if you really want it expectedType: IfStmtSyntax.self
is likely not what you intended :P. Self.self
? Also odd that we use StmtSyntax
, I assume that's because the majority of these are statements. Could split it into StmtHasTrailing...
and DeclHasTrailing...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not a huge fan of this one, but if you really want it
expectedType: IfStmtSyntax.self
is likely not what you intended :P.Self.self
?
Oh, absolutely. Yes. Again, copy-paste error from the IfStmt
below.
Also odd that we use
StmtSyntax
, I assume that's because the majority of these are statements. Could split it intoStmtHasTrailing...
andDeclHasTrailing…
?
Note how the extension above is
where Self: StmtSyntaxProtocol
so all nodes to which this applies are statement nodes. All non-statement nodes have to provide their own implementation like CatchClauseSyntax
does.
self.body = CodeBlockSyntax(statements: bodyBuilder()) | ||
} | ||
} | ||
|
||
extension CatchClauseSyntax: HasTrailingCodeBlock {} | ||
extension CatchClauseSyntax: HasTrailingCodeBlock { | ||
public init(_ signature: PartialSyntaxNodeString, @CodeBlockItemListBuilder bodyBuilder: () -> CodeBlockItemListSyntax) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signature
seems weird to use here (and for the others).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about header
? Since the rest is the body and HTML has header and body? Or do you have better ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that better than signature
, yeah.
ExpressibleByStringLiteral
032ebda
to
bbfec76
Compare
@swift-ci Please test |
…StringLiteral` This removes the implicit expressibility by string literals for all decl/stmt/... nodes, which parsed the node as a decl/stmt/... and then cast it to the expected type. rdar://104090218
bbfec76
to
9fc8f19
Compare
@swift-ci Please test |
@swift-ci Please test macOS |
This removes the implicit expressibility by string literals for all decl/stmt/... nodes, which parsed the node as a decl/stmt/... and then cast it to the expected type.
rdar://104090218