Skip to content

Bugfix/ipconfig skips protocols#346

Open
AnthonyTTaylor wants to merge 2 commits intouber:masterfrom
AnthonyTTaylor:bugfix/ipconfig-skips-protocols
Open

Bugfix/ipconfig skips protocols#346
AnthonyTTaylor wants to merge 2 commits intouber:masterfrom
AnthonyTTaylor:bugfix/ipconfig-skips-protocols

Conversation

@AnthonyTTaylor
Copy link
Copy Markdown

@AnthonyTTaylor AnthonyTTaylor commented Apr 6, 2026

This PR fixes a regression where protocols (and other mockable entities) inside #if blocks were not being discovered for mock generation. The issue was introduced by changes in PR #328 that made the visitor treat all non-fileMacro #if blocks as conditional import
blocks, even when they contained declarations like protocols.

Problem

For non-fileMacro #if blocks, the visitor now always:

  1. Parses the block as a ConditionalImportBlock
  2. Returns .skipChildren

This is correct for import-only blocks, but incorrect for blocks containing declarations. In those cases, protocols, classes, and other declarations are never visited, so mockable entities are not discovered.

Solution

Only treat an #if block as a conditional import block when it contains imports exclusively.

Added a new recursive method containsOnlyImports in EntityVisitor that checks if an IfConfigDeclSyntax contains only:

  • import declarations
  • nested #if blocks that themselves contain only imports

If the block contains anything else (like protocol, class, etc.), the visitor now returns .visitChildren so entity discovery proceeds normally.

Behavior After This Change

  • Import-only #if blocks continue to be parsed as conditional imports
  • #if blocks containing mockable protocols or other declarations are traversed
  • Mixed blocks fall back to child traversal
  • Nested #if blocks are handled recursively

Only treat #if config blocks as conditional imports when they contain imports exclusively. This preserves existing import parsing while allowing the visitor to traverse blocks that contain @mockable protocols or other declarations.
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.

1 participant