Skip to content

Various -fvalidate-ide-info failures on HEAD involving type variable scoping

If you compile the following file with GHC HEAD using -fwrite-ide-info -fvalidate-ide-info:

{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where

newtype List a = MkList [a]
deriving via forall a. [a] instance Eq a => Eq (List a)

class C a where
  m :: forall b. a -> b -> b
  m _ = undefined @_ @a `seq` id @b

instance C [a] where
  m :: forall b. [a] -> b -> b
  m _ = undefined @_ @a `seq` id @b

type family T a
type instance T [a] = a

You will get a volley of errors:

$ ~/Software/ghc5/inplace/bin/ghc-stage2 Bug.hs -fforce-recomp -fwrite-ide-info -fvalidate-ide-info
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
Got invalid scopes
Name b Defined at Bug.hs:17:15 at position Bug.hs:18:35 doesn't occur in calculated scope [LocalScope Bug.hs:17:18-30,
                                                                                           LocalScope Bug.hs:14:3-35]
Name a Defined at Bug.hs:10:21 at position Bug.hs:10:40 doesn't occur in calculated scope [LocalScope Bug.hs:10:24-26]
Name a Defined at Bug.hs:10:21 at position Bug.hs:10:54 doesn't occur in calculated scope [LocalScope Bug.hs:10:24-26]
Got roundtrip errors
LocalName a{tv} Bug.hs:21:17-19 and LocalName a{tv} Bug.hs:21:1-23 do not match
In Node:
([(Right a{tv agy},
   Details:  Nothing {type variable binding with scope: LocalScope Bug.hs:21:15-23 , type variable scopes: LocalScope Bug.hs:21:1-23})],
 Bug.hs:21:17-19)
and
([(Right a{tv r1lk},
   Details:  Nothing {type variable binding with scope: LocalScope Bug.hs:21:15-23 , type variable scopes: LocalScope Bug.hs:21:1-23})],
 Bug.hs:21:17-19)
While comparing
[(Right LocalName a{tv} Bug.hs:21:17-19,
  Details:  Nothing {type variable binding with scope: LocalScope Bug.hs:21:15-23 , type variable scopes: LocalScope Bug.hs:21:1-23})]
and
[(Right LocalName a{tv} Bug.hs:21:1-23,
  Details:  Nothing {type variable binding with scope: LocalScope Bug.hs:21:15-23 , type variable scopes: LocalScope Bug.hs:21:1-23})]

I noticed these when perusing the code in GHC.Iface.Ext.Ast recently. cc @wz1000

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information