Holmusk / elm-street

:deciduous_tree: Crossing the road between Haskell and Elm
Mozilla Public License 2.0
88 stars 6 forks source link

Generation of function names isn't namespace aware. #113

Open turboMaCk opened 3 years ago

turboMaCk commented 3 years ago

for code like (note the elmConstructFields):

newtype RichText =
    RichText Aeson.Value
    deriving stock (Show)
    deriving (FromJSON, ToJSON) via Aeson.Value

instance Elm RichText where
    toElmDefinition _ = DefType $
        ElmType
            { elmTypeName = "RichText"
            , elmTypeVars = []
            , elmTypeIsNewtype = False
            , elmTypeConstructors = ElmConstructor
                { elmConstructorName = "RichText"
                , elmConstructorFields = [ RefCustom $ TypeName "Json.Decode.Value" ]
                } :| []
            }

(and provided one can overcome https://github.com/Holmusk/elm-street/issues/112 witch something like sed -e '/import Time exposing (Posix)/ a import Json.Decode' -i Generated/Types.elm)

elm street will generate decoder and encoding function like:

T.RichText x1 -> [("tag", E.string "RichText"), ("contents", encodeJson.Decode.Value x1)]

which is obviously not correct. Perhaps things like TypeName should contain qualified modules namespace.