diff options
author | M Farkas-Dyck <strake888@proton.me> | 2022-09-29 01:03:13 -0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-10-19 10:46:29 -0400 |
commit | 83638dce4e20097b9b7073534e488a92dce6e88f (patch) | |
tree | e18b4b2484354c8875914a4b35a37d0377258eb4 /compiler/GHC/Tc/Deriv/Generate.hs | |
parent | f7b7a3122185222d5059e37315991afcf319e43c (diff) | |
download | haskell-83638dce4e20097b9b7073534e488a92dce6e88f.tar.gz |
Scrub various partiality involving lists (again).
Lets us avoid some use of `head` and `tail`, and some panics.
Diffstat (limited to 'compiler/GHC/Tc/Deriv/Generate.hs')
-rw-r--r-- | compiler/GHC/Tc/Deriv/Generate.hs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/compiler/GHC/Tc/Deriv/Generate.hs b/compiler/GHC/Tc/Deriv/Generate.hs index 49d97e81e1..e51eee9841 100644 --- a/compiler/GHC/Tc/Deriv/Generate.hs +++ b/compiler/GHC/Tc/Deriv/Generate.hs @@ -1403,7 +1403,6 @@ gen_Data_binds loc (DerivInstTys{dit_rep_tc = rep_tc}) where data_cons = tyConDataCons rep_tc n_cons = length data_cons - one_constr = n_cons == 1 ------------ gfoldl gfoldl_bind = mkFunBindEC 3 loc gfoldl_RDR id (map gfoldl_eqn data_cons) @@ -1420,11 +1419,11 @@ gen_Data_binds loc (DerivInstTys{dit_rep_tc = rep_tc}) ------------ gunfold gunfold_bind = mkSimpleGeneratedFunBind loc gunfold_RDR - [k_Pat, z_Pat, if one_constr then nlWildPat else c_Pat] + [k_Pat, z_Pat, if n_cons == 1 then nlWildPat else c_Pat] gunfold_rhs gunfold_rhs - | one_constr = mk_unfold_rhs (head data_cons) -- No need for case + | [con] <- data_cons = mk_unfold_rhs con -- No need for case | otherwise = nlHsCase (nlHsVar conIndex_RDR `nlHsApp` c_Expr) (map gunfold_alt data_cons) |