Skip to content

`isBuiltInOcc_maybe` must not consider `Tuple`-names as builtin

Summary

isBuiltInOcc_maybe is a shortcut for renaming RdrName of built-in occurrences like ->, [], (), (#,,,#) and so on. It doesn't consider module from where a name goes on because it must not be possible to redefine such names.

However, that doesn't work for newly introduced CUnit, Unit#, Tuple42 and all other tuple names - it's totally fine to redefine them. Shortcutting for such names must be (and it is!) in isPunOcc_maybe function, that consider module of a name properly.

However, isBuiltInOcc_maybe also performs this shortcutting for

  • CUnit, Unit, Unit#
  • CSolo, Solo
  • CTuple<n>, Tuple<n>, Tuple<n>#, Sum<n>#

Steps to reproduce

You can trick this in any code path that uses isBuiltInOcc_maybe, e.g.:

{-# LANGUAGE TemplateHaskell #-}
module T where

import Language.Haskell.TH

data Tuple2 a b = MkTuple2 a b

f :: a -> b -> $(conT (mkName "Tuple2")) a b
f = MkTuple2

Produces such error:

    • Couldn't match type: Tuple2 a b
                     with: (a, b)
      Expected: a -> b -> (a, b)
        Actual: a -> b -> Tuple2 a b

Expected behavior

No errors, the code below is totally fine.

Environment

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