Skip to content

DataClassResolver→ClassResolver; 192 tests pass#53

Merged
MessiasLima merged 3 commits into
mainfrom
opencode/issue46-20260605115752
Jun 9, 2026
Merged

DataClassResolver→ClassResolver; 192 tests pass#53
MessiasLima merged 3 commits into
mainfrom
opencode/issue46-20260605115752

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

All tests pass (192 tests). Here's a summary of the changes:

New files:

  • src/main/kotlin/dev/appoutlet/some/exception/SomeInstantiationException.kt - Custom exception thrown when all constructors fail, with class name and per-constructor failure summary
  • src/main/kotlin/dev/appoutlet/some/resolver/ClassResolver.kt - Renamed from DataClassResolver, now iterates over all constructors (not just primary), falls back to next constructor on failure, propagates SomeCircularReferenceException
  • src/test/kotlin/dev/appoutlet/some/resolver/ClassResolverTest.kt - 16 unit tests covering: primary constructor, secondary-only constructor, fallback to secondary, empty constructor, all-fail exception, canResolve rejections (String, Int, List, Set, Map, abstract class, sealed class), canResolve acceptances, private constructor via reflection, integration test with some<T>()

Modified files:

  • src/main/kotlin/dev/appoutlet/some/config/SomeConfig.kt - Updated import and references from DataClassResolver to ClassResolver
  • AGENTS.md - Updated resolver registration order entry

Deleted files:

  • src/main/kotlin/dev/appoutlet/some/resolver/DataClassResolver.kt

Key design decisions:

  • canResolve() rejects abstract classes via Modifier.isAbstract(kClass.java.modifiers), ensuring sealed classes and interfaces are also excluded
  • SomeCircularReferenceException re-thrown immediately (not caught) to preserve circular-reference diagnostics
  • Private constructors can be resolved via isAccessible = true reflection — documented behavior confirmed by test
  • Constructor order follows KClass.constructors iteration order (primary first, then secondary in declaration order)

Closes #46

New%20session%20-%202026-06-05T11%3A57%3A51.534Z
opencode session  |  github run

Co-authored-by: MessiasLima <MessiasLima@users.noreply.github.com>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

/oc add a trailing line

Comment thread src/main/kotlin/dev/appoutlet/some/resolver/ClassResolver.kt
@opencode-agent

opencode-agent Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Trailing newline added.

New%20session%20-%202026-06-05T21%3A33%3A09.331Z
opencode session  |  github run

@opencode-agent

opencode-agent Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

The resolve method is generally well-structured, but there are a couple of improvements that would make it more explicit and robust:

  1. Unsafe cast on line 111type.classifier as KClass<*> will throw a ClassCastException if canResolve wasn't called first. A safer pattern would be:
val kClass = type.classifier as? KClass<*>
    ?: throw SomeInstantiationException(type.classifier, listOf("Type classifier is not a KClass"))
  1. Broad catch (e: Exception) — This is correct in intent (any failure means "try next constructor"), but it silently swallows truly unexpected errors (e.g., OutOfMemoryError). Consider catching more specific exceptions or at least adding an inline comment explaining the intent.

  2. The SomeCircularReferenceException re-throw pattern is correct and necessary — it's the standard way to exclude specific exceptions from a broad catch. This is clear as-is.

Overall the logic is sound. The biggest improvement would be replacing the unchecked cast with an explicit error — it would make the contract self-enforcing rather than relying on canResolve being called first. Want me to make these changes?

New%20session%20-%202026-06-05T21%3A33%3A10.621Z
opencode session  |  github run

@MessiasLima MessiasLima merged commit a739b2e into main Jun 9, 2026
1 check passed
@MessiasLima MessiasLima deleted the opencode/issue46-20260605115752 branch June 9, 2026 13:40
@github-project-automation github-project-automation Bot moved this from Ready to Done in Some Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Rename DataClassResolver to ClassResolver and support multiple constructors

1 participant