Skip to content

-Wterm-variable-capture fires where it should not

Summary

In my MR !10385 @torsten.schmits gave the code example that should work according to the scoping, but it doesn't with my changes. Then I understand, that -Wterm-variable-capture suffers from the same problem.

Steps to reproduce

{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wterm-variable-capture #-}
module T where

import GHC.Types (Type)

k = 12

class C k a where
  type AT a :: k -> Type

Will output the warning:

T.hs:10:16: warning: [GHC-54201] [-Wterm-variable-capture]
    The type variable ‘k’ is implicitly quantified,
    even though another variable of the same name is in scope:
      ‘k’ defined at T.hs:7:1
    This is not forward-compatible with a planned GHC extension, RequiredTypeArguments.
    Suggested fix: Consider renaming the type variable.
   |
10 |   type AT a :: k -> Type
   |                ^

Expected behavior

No warning should be produced, since k is bounded at type class head and this code doesn't produce the warning:

{-# OPTIONS_GHC -Wterm-variable-capture #-}
module T where

k = 12

id :: forall k . k -> k
id a = a

Environment

  • GHC version used: master branch
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information