Skip to content

Commit eff69a7

Browse files
authored
Don't use record notation for single-field datacons in tactics (#1456)
* Don't use record notation for single-field datacons * Comment as to why this new check is here
1 parent c2f54a2 commit eff69a7

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ mkCon dcon (fmap unLoc -> args)
2121
| dataConIsInfix dcon
2222
, (lhs : rhs : args') <- args =
2323
noLoc $ foldl' (@@) (op lhs (coerceName dcon_name) rhs) args'
24-
| Just fields <- getRecordFields dcon =
24+
| Just fields <- getRecordFields dcon
25+
, length fields >= 2 = -- record notation is unnatural on single field ctors
2526
noLoc $ recordConE (coerceName dcon_name) $ do
2627
(arg, (field, _)) <- zip args fields
2728
pure (coerceName field, arg)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ spec = do
151151
autoTest "GoldenArbitrary.hs" 25 13
152152
autoTest "FmapBoth.hs" 2 12
153153
autoTest "RecordCon.hs" 7 8
154+
autoTest "NewtypeRecord.hs" 6 8
154155
autoTest "FmapJoin.hs" 2 14
155156
autoTest "Fgmap.hs" 2 9
156157
autoTest "FmapJoinInLet.hs" 4 19
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
newtype MyRecord a = Record
2+
{ field1 :: a
3+
}
4+
5+
blah :: (a -> Int) -> a -> MyRecord a
6+
blah = _
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
newtype MyRecord a = Record
2+
{ field1 :: a
3+
}
4+
5+
blah :: (a -> Int) -> a -> MyRecord a
6+
blah _ = Record
7+

0 commit comments

Comments
 (0)