Skip to content

Address dangerous GPlate default in Plated typeclass#58

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/creepy-snake
Draft

Address dangerous GPlate default in Plated typeclass#58
Copilot wants to merge 5 commits intomasterfrom
copilot/creepy-snake

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

The Plated typeclass's default implementation using GPlate silently ignores fields without Generic instances, causing incomplete traversals with no compiler warning.

Changes

  • Made Constraint loc instance explicit - The only production instance relying on the unsafe default now has manual pattern matching that explicitly handles all constructors
  • Enhanced typeclass documentation - Added warnings with concrete example of silent failure case, clarified Generic refers to GHC.Generics.Generic
  • Documented intentional GPlate usage in AST types - Added comments explaining the 4 fallback instances in DataPlated.hs are intentional and type-safe by design

Example of the danger

-- Before: silently skips Baz field during traversal
data Foo = Foo Bar Baz deriving Generic
data Bar = Bar Foo deriving Generic  -- OK: has Generic
data Baz = Baz Foo                   -- PROBLEM: no Generic
instance Plated Foo  -- uses GPlate default, won't traverse Baz!

-- After: explicit implementation or strong warning
instance Plated Foo where
  plate f (Foo bar baz) = Foo <$> f bar <*> pure baz  -- intentional

All 9 Plated instances in the codebase are now either explicit or documented as intentionally using GPlate.

Original prompt

Work on TODO: this is a dangerous function if any component doesn't have Generic instance (from src/Prelude.hs)

Created from VS Code via the GitHub Pull Request extension.


💡 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 3 commits January 13, 2026 17:54
- Add explicit Plated instance for Constraint loc
- Improve documentation with warnings about GPlate dangers
- Remove TODO comment and address the safety concern

Co-authored-by: bristermitten <18754735+bristermitten@users.noreply.github.com>
Add clarifying comments explaining that the GPlate-based fallback
instances in DataPlated.hs are intentional and rely on type-system
enforced Generic instances for AST types.

Co-authored-by: bristermitten <18754735+bristermitten@users.noreply.github.com>
Add a clear example showing how a type without Generic would be
silently skipped during traversal. Clarify that Generic refers
to GHC.Generics.Generic.

Co-authored-by: bristermitten <18754735+bristermitten@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dangerous function for generic instances in Prelude Address dangerous GPlate default in Plated typeclass Jan 13, 2026
Copilot AI requested a review from bristermitten January 13, 2026 18:03
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.

2 participants