Skip to content

Implement compile-time witness resolution verification#15

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/implement-annotation-processor
Closed

Implement compile-time witness resolution verification#15
Copilot wants to merge 3 commits into
mainfrom
copilot/implement-annotation-processor

Conversation

Copilot AI commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Adds a JavaC compiler plugin that verifies witness(Ty<T>) calls will succeed at compile time, catching resolution failures (not found, ambiguous) before runtime.

Implementation

  • WitnessResolutionProcessor: JavaC Plugin that scans AST for TypeClasses.witness() calls, extracts type arguments, and runs WitnessResolution.resolve() at compile time
  • Plugin registration: Added META-INF/services/com.sun.source.util.Plugin for automatic discovery
  • Tests: Demonstrates valid/invalid resolution cases (processor cannot self-bootstrap, so tests document expected behavior)
  • Documentation: ANNOTATION_PROCESSOR.md covers usage in external projects

Usage

Add to compiler configuration:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <compilerArgs>
      <arg>-Xplugin:WitnessResolutionChecker</arg>
    </compilerArgs>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>com.garciat.typeclasses</groupId>
      <artifactId>java-type-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
</plugin>

Compilation will fail with clear diagnostics:

// Compile error: "Witness resolution will fail at runtime:
// No witness found for type: NoWitnessType"
TestShow<NoWitnessType> show = witness(new Ty<>() {});

Notes

Uses Plugin API (not standard annotation processing) to access method invocation AST. Reuses runtime resolution logic for consistency.

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement annotation processor</issue_title>
<issue_description>We can try implementing an annotation processor that verifies, at compile time, that a call to <T> T witness(Ty<T> ty) will succeed in terms of witness constructor resolution, per our resolution rules as described in the README file and as implemented in the library code.

(Witness instantiation (calling the constructors) is a separate issue.)</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 15, 2025 17:34
Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
…tion

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement annotation processor for witness verification Implement compile-time witness resolution verification Dec 15, 2025
Copilot AI requested a review from Garciat December 15, 2025 17:45
@codecov

codecov Bot commented Dec 15, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.79%. Comparing base (09cfa6d) to head (96eaea6).

Files with missing lines Patch % Lines
...eclasses/processor/WitnessResolutionProcessor.java 0.00% 72 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #15      +/-   ##
============================================
- Coverage     68.04%   60.79%   -7.25%     
  Complexity      234      234              
============================================
  Files            49       50       +1     
  Lines           604      676      +72     
  Branches         46       59      +13     
============================================
  Hits            411      411              
- Misses          170      242      +72     
  Partials         23       23              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Garciat Garciat closed this Dec 16, 2025
@Garciat Garciat deleted the copilot/implement-annotation-processor branch December 16, 2025 14:56
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.

Implement annotation processor

2 participants