Skip to content

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 28, 2023

We should not crash the process if the source code that you use to create a syntax node using string interpolation is invalid. Instead we should:

  • Not check for errors in the normal string interpolation case and just return a syntax tree that has the hasError flag set when there are syntax errors
  • In either SwiftSyntaxBuilder offer init(validating node: Self) throws that check that node has no sytnax errors and throws otherwise. This allows us write e.g. try wDeclSyntax(validating: "struct Foo {}") to create a DeclSyntax that’s guaranteed to not have any syntax errors.

I’m not sure yet whether CodeGeneration should use init(validating:) with try! sprayed all over the place or have something like init(checking:) that fatalErrors if the syntax is not valid.

rdar://104423126

@ahoppen ahoppen requested review from bnbarham and kimdv January 28, 2023 14:34
@ahoppen
Copy link
Member Author

ahoppen commented Jan 28, 2023

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/string-interpolation-no-fatalerror branch from 4ad0a0d to 82e5258 Compare January 28, 2023 14:35
@ahoppen
Copy link
Member Author

ahoppen commented Jan 28, 2023

@swift-ci Please test

@bnbarham
Copy link
Contributor

Whoops, pretend my #1291 comments were here 😅

We should not crash the process if the source code that you use to create a syntax node using string interpolation is invalid. Instead we should:

- Not check for errors in the normal string interpolation case and just return a syntax tree that has the `hasError` flag set when there are syntax errors
- In either SwiftSyntaxBuilder offer `init(validating node: Self) throws` that check that `node` has no sytnax errors and throws otherwise. This allows us write e.g. `try wDeclSyntax(validating: "struct Foo {}")` to create a `DeclSyntax` that’s guaranteed to not have any syntax errors

rdar://104423126
@ahoppen ahoppen force-pushed the ahoppen/string-interpolation-no-fatalerror branch from 82e5258 to 21e5eaa Compare January 31, 2023 07:52
@ahoppen
Copy link
Member Author

ahoppen commented Jan 31, 2023

@swift-ci Please test

@ahoppen ahoppen merged commit 64cabae into swiftlang:main Jan 31, 2023
@ahoppen ahoppen deleted the ahoppen/string-interpolation-no-fatalerror branch January 31, 2023 10:55
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