Skip to content

[Parse] Fix nested ifConfig compiler checks #74415

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
merged 3 commits into from
Jun 15, 2024

Conversation

kabiroberai
Copy link
Contributor

The parser is supposed to avoid looking inside unmatched #if compiler (et al) blocks. This usually means that the following code builds fine

#if compiler(>=100)
foo bar
#endif

however, a logical bug meant that if the check was nested inside an already-inactive #if block, it would not adhere to this evaluation-skipping behavior

#if false
#if compiler(>=100)
foo bar // error!
#endif
#endif

This PR fixes this specific case.

@kabiroberai
Copy link
Contributor Author

I'm unsure if this fix needs to be ported to SwiftSyntax as well — I couldn't find the "skip parsing unmatched compiler checks" logic there. If it exists, could someone please point me to it?

@kabiroberai kabiroberai changed the title Fix nested ifConfig compiler checks [Parse] Fix nested ifConfig compiler checks Jun 14, 2024
@rintaro
Copy link
Member

rintaro commented Jun 14, 2024

The change looks good to me. Thanks!
swift-syntax doesn't support skipping regions, for now. So no need to fix this in swift-syntax side.

@kabiroberai Could you squash the change and add relevant commit message? Or I if you write it here, I can squash and add the comment when merging.

@kabiroberai
Copy link
Contributor Author

@rintaro feel free to use the issue title: "[Parse] Fix nested ifConfig compiler checks". Thanks!

@rintaro
Copy link
Member

rintaro commented Jun 14, 2024

@swift-ci Please smoke test

@rintaro
Copy link
Member

rintaro commented Jun 14, 2024

OK, but I hope to put more explanation in the comment.
Let's just use the description:

[Parse] Fix nested ifConfig compiler checks

The parser is supposed to avoid looking inside unmatched `#if` compiler (et al) blocks.
This usually means that the following code builds fine

  #if compiler(>=100)
  foo bar
  #endif
  
however, a logical bug meant that if the check was nested inside an already-inactive
`#if` block, it would not adhere to this evaluation-skipping behavior

  #if false
  #if compiler(>=100)
  foo bar // error!
  #endif
  #endif
  
This PR fixes this specific case.

@rintaro rintaro merged commit d4ee050 into swiftlang:main Jun 15, 2024
3 checks passed
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request Jun 20, 2024
The parser is supposed to avoid looking inside unmatched `#if` compiler (et al) blocks.
This usually means that the following code builds fine

  #if compiler(>=100)
  foo bar
  #endif
  
however, a logical bug meant that if the check was nested inside an already-inactive
`#if` block, it would not adhere to this evaluation-skipping behavior

  #if false
  #if compiler(>=100)
  foo bar // error!
  #endif
  #endif
  
This PR fixes this specific case.
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.

2 participants