Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,249
    • Issues 4,249
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 391
    • Merge Requests 391
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18259

Closed
Open
Opened May 29, 2020 by infinity0@infinity0

False-positive redundant-constraint warning on constrained default instance method

Tested on GHC 8.10.1:

{-# LANGUAGE DefaultSignatures #-}

{-# OPTIONS_GHC -Werror -Wredundant-constraints #-}

class Base a where
  myList :: [a]
  default myList :: SubClass a => [a]
  myList = defaultMyList

class Base a => SubClass a where
  myList2 :: [a]

defaultMyList :: SubClass a => [a]
defaultMyList = myList2

main :: IO ()
main = pure ()

The error is as follows:

Test.hs:7:11: error: [-Wredundant-constraints, -Werror=redundant-constraints]
    • Redundant constraint: Base a
    • In the type signature for:
           myList :: forall a. (Base a, SubClass a) => [a]
      In the ambiguity check for ‘myList’
      To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
      When checking the class method: myList :: forall a. Base a => [a]
  |
7 |   default myList :: SubClass a => [a]
  |           ^^^^^^

suggesting that some automatic process is adding (Base a) as an implicit constraint, but then this redundancy check is failing on the automatically-added constraint - which it shouldn't because the programmer can't do anything about it.

Adding AllowAmbiguousTypes does make the error go away, as the error message suggests, however the type is not ambiguous - there is no false-positive for defaultMyList with the same (source-level) signature. Adding ConstrainedClassMethods makes no difference.

Edited May 29, 2020 by infinity0
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#18259