Skip to content

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
ffried added a commit to sersoft-gmbh/color-components that referenced this pull request Sep 18, 2025
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