Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • 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,977
    • Issues 4,977
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 483
    • Merge requests 483
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18148
Closed
Open
Created May 06, 2020 by Koz Ross@kozross

ConstrainedClassMethods can trigger un-actionable redundant constraint warnings together with GND

Summary

If you use GeneralizedNewtypeDeriving (or indeed, DerivingVia) to derive an instance of a type class whose methods have constraints that aren't in the type class head, it is possible to trigger redundant constraint warnings if the generated code would cause the constraints to be satisfied by whatever the type variables are set to. See the example given in 'steps to reproduce' for a demonstration. These warnings can't be actioned - the only option currently is to disable redundant constraint warnings completely.

Steps to reproduce

Attempt to compile the following code with -Wredundant-constraints enabled:

{-# LANGUAGE ConstrainedClassMethods #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}

module Baz where

class Foo a where
  bar :: (Num a) => a -> a
  bar = (+ 1)

instance Foo Int

newtype Quux a = Quux a

deriving newtype instance Foo (Quux Int)

This will emit a redundant constraint warning, as Int is already an instance of Num.

Expected behavior

Should compile, emitting no warnings.

Environment

  • GHC version used: 8.10.1

Optional:

  • Operating System: GNU/Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking