Skip to content

Bugfix/#138 resolve ambiguity with wrap method in preview wrapper - #139

Merged
sergio-sastre merged 3 commits into
masterfrom
bugfix/#138_Resolve_ambiguity_with_wrap_method_in_previewWrapper
Aug 7, 2026
Merged

Bugfix/#138 resolve ambiguity with wrap method in preview wrapper#139
sergio-sastre merged 3 commits into
masterfrom
bugfix/#138_Resolve_ambiguity_with_wrap_method_in_previewWrapper

Conversation

@sergio-sastre

@sergio-sastre sergio-sastre commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved preview wrapper detection to select only compatible Wrap methods.
    • Prevented incorrect overloads from being selected during preview scanning.
  • Tests
    • Expanded test coverage for overloaded and incompatible wrapper methods.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a59e3d4-4a95-4f69-ab5a-75f33f1eb17f

📥 Commits

Reviewing files that changed from the base of the PR and between 1cd5970 and 4e44424.

📒 Files selected for processing (1)
  • tests/src/main/java/sergio/sastre/composable/preview/scanner/android/previewwrapper/Composables.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/src/main/java/sergio/sastre/composable/preview/scanner/android/previewwrapper/Composables.kt

Walkthrough

The scanner now selects Wrap only when its parameter count and types match the expected composable wrapper signature. Test fixtures add overloads for invalid reflection matches.

Changes

Wrap method matching

Layer / File(s) Summary
Validate Wrap reflection signatures
core/src/main/java/.../ComposablePreview.kt, tests/src/main/java/.../Composables.kt
getProviderAndWrapMethod validates the Wrap parameter count and types. Test wrappers cover excess parameters, non-composable content, and signature lookalikes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 138: The change tightens Wrap reflection matching and adds overloads for the incorrect-match cases described by the issue.

Poem

A rabbit checks each Wrap with care,
Three slots must match the pattern there.
Function2 and Composer align,
False lookalikes leave the line.
“Hop!” says the scanner, “Now I know!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the bug fix: resolving ambiguity when selecting the Wrap method in the preview wrapper.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/#138_Resolve_ambiguity_with_wrap_method_in_previewWrapper

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
core/src/main/java/sergio/sastre/composable/preview/scanner/core/preview/ComposablePreview.kt (1)

110-115: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Validate the Wrap third parameter in the predicate.

The scanner expects Wrap(Function2, Composer, Int), but the current filter accepts any third type. Pass Int for change tracking, so an overload such as Wrap(Function2, Composer, String) can fail at wrapMethod.invoke(...). Include the third-type check instead of relying on the cache comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@core/src/main/java/sergio/sastre/composable/preview/scanner/core/preview/ComposablePreview.kt`
around lines 110 - 115, Update the `Wrap` method predicate in
`ComposablePreview` to validate that the third parameter type is `Int` in
addition to the existing name, count, and first two parameter checks, ensuring
only `Wrap(Function2, Composer, Int)` is selected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@core/src/main/java/sergio/sastre/composable/preview/scanner/core/preview/ComposablePreview.kt`:
- Around line 110-115: Update the Wrap method lookup in PreviewWrapperCache to
uniquely select the intended overload using the exact third parameter type (or
reject ambiguous matches), rather than relying on declaredMethods order;
preserve invocation with the expected content, composer, and changed arguments,
and add a runtime regression assertion confirming PublicScaffoldWrapper
succeeds.

In
`@tests/src/main/java/sergio/sastre/composable/preview/scanner/android/previewwrapper/Composables.kt`:
- Around line 45-49: Update the lookalike Wrap fixture in Composables.kt to be
non-@Composable and use a descriptor such as (Function2, String), ensuring it
remains a three-parameter reflection match without compiler-generated
parameters. Preserve the existing overriding Wrap selection behavior and revise
the misleading bytecode comment accordingly.

---

Nitpick comments:
In
`@core/src/main/java/sergio/sastre/composable/preview/scanner/core/preview/ComposablePreview.kt`:
- Around line 110-115: Update the `Wrap` method predicate in `ComposablePreview`
to validate that the third parameter type is `Int` in addition to the existing
name, count, and first two parameter checks, ensuring only `Wrap(Function2,
Composer, Int)` is selected.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cb46cbbc-8225-42cd-8dc8-b8b7ae506cdb

📥 Commits

Reviewing files that changed from the base of the PR and between b90e08d and 1cd5970.

📒 Files selected for processing (2)
  • core/src/main/java/sergio/sastre/composable/preview/scanner/core/preview/ComposablePreview.kt
  • tests/src/main/java/sergio/sastre/composable/preview/scanner/android/previewwrapper/Composables.kt

@sergio-sastre
sergio-sastre merged commit ee2bb28 into master Aug 7, 2026
8 checks passed
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.

Ambiguity in PreviewWrapperProvider: Overloaded Wrap Method Resolves to the Incorrect Overload

1 participant