Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,843
    • Issues 4,843
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19465

Closed
Open
Created Mar 01, 2021 by Ollie Charles@ocharles

Don't allow deriving-via when the via type is identical to the type intsances are being derived for

Summary

Currently we can use DerivingVia to derive an instance via the very type that we're trying to define an instance for:

❯ ghci
GHCi, version 8.10.3: https://www.haskell.org/ghc/  :? for help
Prelude> :set -XDerivingVia
Prelude> data Color = Red | Green | Blue deriving Show via Color
Prelude> show Red
"

This is nonsensical and just leads to infinite recursion at runtime.

While there are plenty of other ways one can shoot themselves in their foot, I suggest that we at least notice this case. I just accidentally introduced this into some code at work when I forget to provide a newtype. I meant to write:

data Foo = ...
  deriving (FromField) via ReadShow Foo

but instead wrote

data Foo = ...
  deriving (FromField) via Foo

Expected behavior

At least trigger a warning, if there are legitimate reasons we might want to have data Foo = ... deriving C via Foo. If there are no legitimate reasons to write this, a compile time error would be emitted.

Environment

  • GHC version used: 8.10.3
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking