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,393
    • Issues 4,393
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 378
    • Merge Requests 378
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #16342

Closed
Open
Opened Feb 20, 2019 by Simon Peyton Jones@simonpjDeveloper

Kind inference crash

Here's a gnarly test case

{-# LANGUAGE MultiParamTypeClasses, TypeInType, ConstrainedClassMethods, ScopedTypeVariables #-}

module Foo where

import Data.Proxy

class C (a::ka) x where
  cop :: D a x => x -> Proxy a -> Proxy a
  cop _ x = x :: Proxy (a::ka)

class D (b::kb) y where
  dop :: C b y => y -> Proxy b -> Proxy b
  dop _ x = x :: Proxy (b::kb)

This crashes every recent GHC outright, with

    • GHC internal error: ‘kb’ is not in scope during type checking, but it passed the renamer
      tcl_env of environment: [avu :-> Type variable ‘b’ = b :: ka,
                               avv :-> Type variable ‘y’ = y :: *,
                               avw :-> Identifier[x::Proxy b, NotLetBound],
                               avx :-> Type variable ‘ka’ = ka :: *]
    • In the kind ‘kb’
      In the first argument of ‘Proxy’, namely ‘(b :: kb)’
      In an expression type signature: Proxy (b :: kb)
   |
13 |   dop _ x = x :: Proxy (b::kb)
   |                            ^^

Yikes.

Reason:

  • C and D are mutually recursive
  • ka and kb get bound to unification variables, and then get unified in the kind-inference phase
  • As a result the utterly-final class for C and D end up with the same TyVar for ka/kb.
  • And then, for one of them, the tyvar is not in scope when (much, much later) we check the default declaration.

Gah! In generaliseTcTyCon I think we may need to do a reverse-map to ensure that each of the final tyConTyVars has the Name from this declaration, rather than accidentally getting a Name from another decl in the mutually recursive group.

Edited Mar 10, 2019 by Simon Peyton Jones
Assignee
Assign to
8.10.1
Milestone
8.10.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#16342