fix: resolve field/2 ambiguous import in inline embeds#2
Merged
Conversation
Inline `embeds_one/embeds_many` with do-blocks previously delegated to `Ecto.Schema.embeds_one/4`, which creates child modules via `Module.create/3` carrying the caller's `__ENV__` — including EctoTypedSchema's `field/2` import. When the child module then `use Ecto.Schema`, both `field/2` imports collide. Fix: create inline child modules ourselves with `use EctoTypedSchema` + `typed_embedded_schema`, then call `Ecto.Schema.__embeds_one__/4` directly. This also gives inline embed modules proper `@type t()` generation, which they previously lacked. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove Ecto.Schema.field() workaround from expected blocks — plain `field` works inside Ecto.Schema inline embed do-blocks too. Add test for multi-level nested inline embeds (parent → Shipping → Address) to verify the fix works recursively. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace regex `=~` assertions with normalized exact `==` matching. normalize_type/1 strips the module prefix and collapses whitespace so assertions are deterministic regardless of module path length. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
field/2 imported from both Ecto.Schema and EctoTypedSchema, call is ambiguouserror when usingfieldinside inlineembeds_one/embeds_manydo-blocks@type t()generation via EctoTypedSchema (previously only got bareEcto.Schemawith no typespec)Root Cause
Ecto.Schema.embeds_one/4calls__embeds_module__(__ENV__, ...)which creates the child module viaModule.create/3carrying the caller's__ENV__— including EctoTypedSchema'sfield/2import. When the child module thenuse Ecto.Schema, bothfield/2imports collide.Fix
Instead of delegating to
Ecto.Schema.embeds_one/4, create inline child modules withuse EctoTypedSchema+typed_embedded_schema, then callEcto.Schema.__embeds_one__/4directly. Addedexpand_nested_module_alias/2to resolve child module names relative to the parent, matching Ecto's own behavior.Test plan
embeds_onecompiles with plainfieldin do-block (was ambiguous import error)embeds_manycompiles with plainfieldin do-block@type t()with correct fieldstyped: [null: false]on inline embeds worksprimary_key: falseforwarded to child moduleon_replace: :deleteEcto opt forwarded correctly🤖 Generated with Claude Code