Skip to content

Use string literals to synthesize the empty string #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,5 @@ buildDataCon jdg dc tyapps = do
) $ zip args [0..]
pure $ ext
& #syn_trace %~ rose (show dc) . pure
& #syn_val %~ mkCon dc
& #syn_val %~ mkCon dc tyapps

24 changes: 14 additions & 10 deletions plugins/hls-tactics-plugin/src/Wingman/CodeGen/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
module Wingman.CodeGen.Utils where

import Data.List
import DataCon
import Development.IDE.GHC.Compat
import GHC.Exts
import GHC.SourceGen (RdrNameStr, recordConE)
import GHC.SourceGen.Overloaded
import Wingman.GHC (getRecordFields)
import Name
import Data.List
import DataCon
import Development.IDE.GHC.Compat
import GHC.Exts
import GHC.SourceGen (RdrNameStr, recordConE, string)
import GHC.SourceGen.Overloaded
import GhcPlugins (nilDataCon, charTy, eqType)
import Name
import Wingman.GHC (getRecordFields)


------------------------------------------------------------------------------
-- | Make a data constructor with the given arguments.
mkCon :: DataCon -> [LHsExpr GhcPs] -> LHsExpr GhcPs
mkCon dcon (fmap unLoc -> args)
mkCon :: DataCon -> [Type] -> [LHsExpr GhcPs] -> LHsExpr GhcPs
mkCon dcon apps (fmap unLoc -> args)
| dcon == nilDataCon
, [ty] <- apps
, ty `eqType` charTy = noLoc $ string ""
| isTupleDataCon dcon =
noLoc $ tuple args
| dataConIsInfix dcon
Expand Down
1 change: 1 addition & 0 deletions plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ spec = do
autoTest 2 9 "Fgmap.hs"
autoTest 4 19 "FmapJoinInLet.hs"
autoTest 9 12 "AutoEndo.hs"
autoTest 2 16 "AutoEmptyString.hs"

failing "flaky in CI" $
autoTest 2 11 "GoldenApplicativeThen.hs"
Expand Down
2 changes: 2 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/AutoEmptyString.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
empty_string :: String
empty_string = _
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
empty_string :: String
empty_string = ""