Skip to content

Commit 7fd7bc0

Browse files
isovectorAilrun
andauthored
Use string literals to synthesize the empty string (#1564)
Co-authored-by: Junyoung/Clare Jang <jjc9310@gmail.com>
1 parent 7346b3d commit 7fd7bc0

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,5 @@ buildDataCon jdg dc tyapps = do
187187
) $ zip args [0..]
188188
pure $ ext
189189
& #syn_trace %~ rose (show dc) . pure
190-
& #syn_val %~ mkCon dc
190+
& #syn_val %~ mkCon dc tyapps
191191

plugins/hls-tactics-plugin/src/Wingman/CodeGen/Utils.hs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
module Wingman.CodeGen.Utils where
22

3-
import Data.List
4-
import DataCon
5-
import Development.IDE.GHC.Compat
6-
import GHC.Exts
7-
import GHC.SourceGen (RdrNameStr, recordConE)
8-
import GHC.SourceGen.Overloaded
9-
import Wingman.GHC (getRecordFields)
10-
import Name
3+
import Data.List
4+
import DataCon
5+
import Development.IDE.GHC.Compat
6+
import GHC.Exts
7+
import GHC.SourceGen (RdrNameStr, recordConE, string)
8+
import GHC.SourceGen.Overloaded
9+
import GhcPlugins (nilDataCon, charTy, eqType)
10+
import Name
11+
import Wingman.GHC (getRecordFields)
1112

1213

1314
------------------------------------------------------------------------------
1415
-- | Make a data constructor with the given arguments.
15-
mkCon :: DataCon -> [LHsExpr GhcPs] -> LHsExpr GhcPs
16-
mkCon dcon (fmap unLoc -> args)
16+
mkCon :: DataCon -> [Type] -> [LHsExpr GhcPs] -> LHsExpr GhcPs
17+
mkCon dcon apps (fmap unLoc -> args)
18+
| dcon == nilDataCon
19+
, [ty] <- apps
20+
, ty `eqType` charTy = noLoc $ string ""
1721
| isTupleDataCon dcon =
1822
noLoc $ tuple args
1923
| dataConIsInfix dcon

plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ spec = do
4747
autoTest 2 9 "Fgmap.hs"
4848
autoTest 4 19 "FmapJoinInLet.hs"
4949
autoTest 9 12 "AutoEndo.hs"
50+
autoTest 2 16 "AutoEmptyString.hs"
5051

5152
failing "flaky in CI" $
5253
autoTest 2 11 "GoldenApplicativeThen.hs"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
empty_string :: String
2+
empty_string = _
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
empty_string :: String
2+
empty_string = ""

0 commit comments

Comments
 (0)