Skip to content

Commit cb68ca2

Browse files
Merge pull request #72 from MercuryTechnologies/joseph/swift-optional-newtype-fix
Fix swift optional newtype
2 parents 16dfdc9 + 60e07a1 commit cb68ca2

File tree

2 files changed

+15
-3
lines changed
  • .golden/swiftBasicNewtypeJoinOptionalsSpec
  • src/Moat/Pretty

2 files changed

+15
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
struct Newtype {
22
typealias NewtypeTag = Tagged<Newtype, Int?>
3-
let value: NewtypeTag
3+
let value: NewtypeTag?
44
}

src/Moat/Pretty/Swift.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ prettySwiftDataWith indent = \case
7878
++ " = Tagged<"
7979
++ newtypeName
8080
++ ", "
81-
++ prettyMoatType (fieldType newtypeField)
81+
++ case (fieldType newtypeField) of
82+
Optional t -> prettyMoatType t
83+
t -> prettyMoatType t
8284
++ ">\n"
8385
++ prettyNewtypeField indents newtypeField newtypeName
8486
++ "}"
@@ -255,7 +257,17 @@ prettyStructFields indents = go
255257
++ go fs
256258

257259
prettyNewtypeField :: String -> Field -> String -> String
258-
prettyNewtypeField indents (Field alias _ _) fieldName = indents ++ "let " ++ alias ++ ": " ++ fieldName ++ "Tag" ++ "\n"
260+
prettyNewtypeField indents (Field alias fieldType _) fieldName =
261+
indents
262+
++ "let "
263+
++ alias
264+
++ ": "
265+
++ fieldName
266+
++ "Tag"
267+
++ case fieldType of
268+
Optional _ -> "?"
269+
_ -> ""
270+
++ "\n"
259271

260272
prettyPrivateTypes :: String -> [MoatData] -> String
261273
prettyPrivateTypes indents = go

0 commit comments

Comments
 (0)