Skip to content

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

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 25, 2023

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

@ahoppen ahoppen requested a review from bnbarham January 25, 2023 18:17
@ahoppen
Copy link
Member Author

ahoppen commented Jan 25, 2023

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/only-base-nodes-expressible-by-string branch from 2d43d17 to 032ebda Compare January 25, 2023 19:57
Comment on lines 46 to 55
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())
}
}
Copy link
Contributor

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...?

Copy link
Member Author

@ahoppen ahoppen Jan 26, 2023

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 into StmtHasTrailing... and DeclHasTrailing…?

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 {
Copy link
Contributor

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).

Copy link
Member Author

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?

Copy link
Contributor

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.

@ahoppen ahoppen changed the title Significantly restrict nodes expressible by string interpolation Don’t automaticaly conform all decl/stmt/etc. nodes to ExpressibleByStringLiteral Jan 26, 2023
@ahoppen ahoppen force-pushed the ahoppen/only-base-nodes-expressible-by-string branch from 032ebda to bbfec76 Compare January 26, 2023 07:54
@ahoppen
Copy link
Member Author

ahoppen commented Jan 26, 2023

@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
@ahoppen ahoppen force-pushed the ahoppen/only-base-nodes-expressible-by-string branch from bbfec76 to 9fc8f19 Compare January 26, 2023 22:03
@ahoppen
Copy link
Member Author

ahoppen commented Jan 26, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jan 26, 2023

swiftlang/swift#63251

@swift-ci Please test macOS

@ahoppen ahoppen merged commit 929dad4 into swiftlang:main Jan 27, 2023
@ahoppen ahoppen deleted the ahoppen/only-base-nodes-expressible-by-string branch January 27, 2023 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants