Skip to content

Commit

Permalink
Merge pull request #72 from MercuryTechnologies/joseph/swift-optional…
Browse files Browse the repository at this point in the history
…-newtype-fix

Fix swift optional newtype
  • Loading branch information
josephsumabat authored Dec 13, 2023
2 parents 16dfdc9 + 60e07a1 commit cb68ca2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .golden/swiftBasicNewtypeJoinOptionalsSpec/golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct Newtype {
typealias NewtypeTag = Tagged<Newtype, Int?>
let value: NewtypeTag
let value: NewtypeTag?
}
16 changes: 14 additions & 2 deletions src/Moat/Pretty/Swift.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ prettySwiftDataWith indent = \case
++ " = Tagged<"
++ newtypeName
++ ", "
++ prettyMoatType (fieldType newtypeField)
++ case (fieldType newtypeField) of
Optional t -> prettyMoatType t
t -> prettyMoatType t
++ ">\n"
++ prettyNewtypeField indents newtypeField newtypeName
++ "}"
Expand Down Expand Up @@ -255,7 +257,17 @@ prettyStructFields indents = go
++ go fs

prettyNewtypeField :: String -> Field -> String -> String
prettyNewtypeField indents (Field alias _ _) fieldName = indents ++ "let " ++ alias ++ ": " ++ fieldName ++ "Tag" ++ "\n"
prettyNewtypeField indents (Field alias fieldType _) fieldName =
indents
++ "let "
++ alias
++ ": "
++ fieldName
++ "Tag"
++ case fieldType of
Optional _ -> "?"
_ -> ""
++ "\n"

prettyPrivateTypes :: String -> [MoatData] -> String
prettyPrivateTypes indents = go
Expand Down

0 comments on commit cb68ca2

Please sign in to comment.