-
Notifications
You must be signed in to change notification settings - Fork 439
Fixed testAvailabilityQueryUnavailability34a #1464
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
Fixed testAvailabilityQueryUnavailability34a #1464
Conversation
@ahoppen I've fixed everything you suggested. However, the fact that I had to introduce two new elements |
The only way I see to fix this specific case public struct RawConditionElementSyntax: RawSyntaxNodeProtocol {
...
public var unexpectedInsteadOfTrailingComma: RawUnexpectedNodesSyntax? {...}
...
} |
Tests/SwiftParserTest/translated/AvailabilityQueryUnavailabilityTests.swift
Outdated
Show resolved
Hide resolved
6367e1c
to
e7dc9a4
Compare
If you don't mind, I would like to resolve the |
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.
Thank you. The PR looks veery good now. I’ve got three local comments but they should be straightforward to fix. After this we can merge it. 🎉
af96c05
to
325f869
Compare
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.
Thank you for improving the diagnostic. This looks good.
@CippoX Could you rebase your PR onto |
325f869
to
f602144
Compare
@ahoppen now everything should be ok 👍 |
Thanks. If CI is happy, I’ll merge it. @swift-ci Please test |
CI failed in one test case, I was curious what it was, debugged it and this diff should fix the problem. Could you apply it to your PR? diff --git a/Sources/SwiftParserDiagnostics/MissingNodesError.swift b/Sources/SwiftParserDiagnostics/MissingNodesError.swift
index 9e17832a6..7faffba2d 100644
--- a/Sources/SwiftParserDiagnostics/MissingNodesError.swift
+++ b/Sources/SwiftParserDiagnostics/MissingNodesError.swift
@@ -112,13 +112,17 @@ func nodesDescription<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format:
func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format: Bool) -> (commonAncestor: Syntax?, description: String) {
let missingSyntaxNodes = nodes.map(Syntax.init)
- // If all tokens in the parent are missing, return the parent type name.
- if let commonAncestor = findCommonAncestor(missingSyntaxNodes),
+ // If all tokens in the parent are missing, return the parent type name unless
+ // we are replacing by a single token that has explicit text, in which case we
+ // return that explicit text.
+ if !isIdentifierWithCustomName,
+ let commonAncestor = findCommonAncestor(missingSyntaxNodes),
commonAncestor.isMissingAllTokens,
let firstToken = commonAncestor.firstToken(viewMode: .all),
let lastToken = commonAncestor.lastToken(viewMode: .all),
missingSyntaxNodes.contains(Syntax(firstToken)),
- missingSyntaxNodes.contains(Syntax(lastToken))
+ missingSyntaxNodes.contains(Syntax(lastToken)),
+ nodes.only?.as(TokenSyntax.self)?.text != nil
{
if let nodeTypeName = commonAncestor.nodeTypeNameForDiagnostics(allowBlockNames: true) {
return (commonAncestor, nodeTypeName) |
sure |
@ahoppen where is |
Oh, sorry, copy-pasted the wrong diff. It should have been diff --git a/Sources/SwiftParserDiagnostics/MissingNodesError.swift b/Sources/SwiftParserDiagnostics/MissingNodesError.swift
index 9e17832a6..7faffba2d 100644
--- a/Sources/SwiftParserDiagnostics/MissingNodesError.swift
+++ b/Sources/SwiftParserDiagnostics/MissingNodesError.swift
@@ -112,13 +112,17 @@ func nodesDescription<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format:
func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format: Bool) -> (commonAncestor: Syntax?, description: String) {
let missingSyntaxNodes = nodes.map(Syntax.init)
if let commonAncestor = findCommonAncestor(missingSyntaxNodes),
- // If all tokens in the parent are missing, return the parent type name.
+ // If all tokens in the parent are missing, return the parent type name unless
+ // we are replacing by a single token that has explicit text, in which case we
+ // return that explicit text.
commonAncestor.isMissingAllTokens,
let firstToken = commonAncestor.firstToken(viewMode: .all),
let lastToken = commonAncestor.lastToken(viewMode: .all),
missingSyntaxNodes.contains(Syntax(firstToken)),
- missingSyntaxNodes.contains(Syntax(lastToken))
+ missingSyntaxNodes.contains(Syntax(lastToken)),
+ nodes.only?.as(TokenSyntax.self)?.text != nil
{
if let nodeTypeName = commonAncestor.nodeTypeNameForDiagnostics(allowBlockNames: true) {
return (commonAncestor, nodeTypeName) |
ba7db24
to
f47c7b2
Compare
All done, and thanks for debugging it! |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
Is So I suggest checking if |
Yes, correct.
I thought that’s essentially what I did with my diff but looks like I was wrong and didn’t run all tests to verify, sorry about that. I don’t think we should add a new function if you could investigate in finding some way to make the current one behave in both scenarios, that’d be great. |
@ahoppen I've pushed my idea, let me know |
I know my solution is very amateur, but it looks quite hard to change |
I just looked into it further and it looks like my previous solution was really close, I just forgot to check for empty string instead of diff --git a/Sources/SwiftParserDiagnostics/MissingNodesError.swift b/Sources/SwiftParserDiagnostics/MissingNodesError.swift
index b5f1215e..3e6b9f34 100644
--- a/Sources/SwiftParserDiagnostics/MissingNodesError.swift
+++ b/Sources/SwiftParserDiagnostics/MissingNodesError.swift
@@ -112,6 +112,13 @@ func nodesDescription<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format:
func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format: Bool) -> (commonAncestor: Syntax?, description: String) {
let missingSyntaxNodes = nodes.map(Syntax.init)
+ let isOnlyTokenWithNonMissingText: Bool
+ if let token = nodes.only?.as(TokenSyntax.self) {
+ isOnlyTokenWithNonMissingText = token.text != ""
+ } else {
+ isOnlyTokenWithNonMissingText = false
+ }
+
// If all tokens in the parent are missing, return the parent type name unless
// we are replacing by a single token that has explicit text, in which case we
// return that explicit text.
@@ -120,7 +127,8 @@ func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [Synta
let firstToken = commonAncestor.firstToken(viewMode: .all),
let lastToken = commonAncestor.lastToken(viewMode: .all),
missingSyntaxNodes.contains(Syntax(firstToken)),
- missingSyntaxNodes.contains(Syntax(lastToken))
+ missingSyntaxNodes.contains(Syntax(lastToken)),
+ !isOnlyTokenWithNonMissingText
{
if let nodeTypeName = commonAncestor.nodeTypeNameForDiagnostics(allowBlockNames: true) {
return (commonAncestor, nodeTypeName)
diff --git a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift
index 52198c2b..fd2af952 100644
--- a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift
+++ b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift
@@ -614,10 +614,6 @@ public struct ReplaceTokensFixIt: ParserFixIt {
public let replacements: [TokenSyntax]
public var message: String {
- if replacements.count == 1 {
- return "replace \(nodesDescription(replaceTokens, format: false)) with '\(replacements[0].text)'"
- } else {
- return "replace \(nodesDescription(replaceTokens, format: false)) with \(nodesDescription(replacements, format: false))"
- }
+ return "replace \(nodesDescription(replaceTokens, format: false)) with \(nodesDescription(replacements, format: false))"
}
}
|
2a9caa7
to
a0fc474
Compare
Thanks! |
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.
Thank you. This looks great now!
@swift-ci Please test |
@swift-ci Please test Windows |
Looks like this PR raced with the one that changed |
Head branch was pushed to by a user without write access
@swift-ci please test |
@kimdv please wait, looks there's something wrong 🥲 |
7e927aa
to
5457d5f
Compare
Honestly, I'm not sure what happened, but everything seems to be fine now. I've also removed a warning introduced by my previous PR. |
5457d5f
to
07fff06
Compare
@swift-ci please test |
Let's see what the CI says 🤞 |
@swift-ci Please test |
Finally 🎉 |
These parser failures were found by swiftlang#1340. - There was one round-trip failure introduced by swiftlang#1464 - A few cases were just consume tokens as the wrong child - The list of expected token kinds of `DeclModifierSynax` didn’t contain one modifier that was actually parsed
These parser failures were found by swiftlang#1340. - There was one round-trip failure introduced by swiftlang#1464 - A few cases were just consume tokens as the wrong child - The list of expected token kinds of `DeclModifierSynax` didn’t contain one modifier that was actually parsed
I'm clearly doing something wrong because Source Control keeps breaking down. Problems aside, I've implemented the changes you suggested and now it looks way better. Unfortunately I am still having trouble fixing this edge case
if #available(*) == false && other_condition