Skip to content

Commit af257c3

Browse files
isovectorAilrun
andauthored
Make sure split respects GADT equalities (#1466)
* Make sure split respects GADT equalities * Unnecessary do Co-authored-by: Junyoung/Clare Jang <jjc9310@gmail.com>
1 parent 00e3577 commit af257c3

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Tactics.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,9 @@ split :: TacticsM ()
191191
split = tracing "split(user)" $ do
192192
jdg <- goal
193193
let g = jGoal jdg
194-
case splitTyConApp_maybe $ unCType g of
194+
case tacticsGetDataCons $ unCType g of
195195
Nothing -> throwError $ GoalMismatch "split" g
196-
Just (tc, _) -> do
197-
let dcs = tyConDataCons tc
198-
choice $ fmap splitDataCon dcs
196+
Just (dcs, _) -> choice $ fmap splitDataCon dcs
199197

200198

201199
------------------------------------------------------------------------------

plugins/hls-tactics-plugin/test/GoldenSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ spec = do
143143
refineTest "RefineReader.hs" 4 8
144144
refineTest "RefineGADT.hs" 8 8
145145

146+
-- test via:
147+
-- stack test hls-tactics-plugin --test-arguments '--match "Golden/golden tests/"'
146148
describe "golden tests" $ do
147149
let autoTest = mkGoldenTest allFeatures Auto ""
148150

151+
autoTest "AutoSplitGADT.hs" 11 8
149152
goldenTest Intros "" "GoldenIntros.hs" 2 8
150153
autoTest "GoldenEitherAuto.hs" 2 11
151154
autoTest "GoldenJoinCont.hs" 4 12
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{-# LANGUAGE GADTs #-}
2+
3+
data GADT b a where
4+
GBool :: b -> GADT b Bool
5+
GInt :: GADT b Int
6+
7+
-- wingman would prefer to use GBool since then it can use its argument. But
8+
-- that won't unify with GADT Int, so it is forced to pick GInt and ignore the
9+
-- argument.
10+
test :: b -> GADT b Int
11+
test = _
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{-# LANGUAGE GADTs #-}
2+
3+
data GADT b a where
4+
GBool :: b -> GADT b Bool
5+
GInt :: GADT b Int
6+
7+
-- wingman would prefer to use GBool since then it can use its argument. But
8+
-- that won't unify with GADT Int, so it is forced to pick GInt and ignore the
9+
-- argument.
10+
test :: b -> GADT b Int
11+
test _ = GInt
12+

0 commit comments

Comments
 (0)