Skip to content

Missing qualifier when referring to a type using the Gen helpers #48

@dillonkearns

Description

@dillonkearns

Hey! Thanks for the awesome tool, really loving it.

I think I found a minor bug. It results in generated code that has a compiler error because it references a type as Effect when it would need to be Effect.Effect to be valid (or expose the type from the import with import Effect exposing (Effect)).

How to reproduce:

I have this code in my codebase in app/Effect.elm

module Effect exposing (Effect(..), batch, fromCmd, map, none, perform)

{-| -}
none : Effect msg
none =
    None

{-| -}
type Effect msg
    = None
 -- | ...

I tell elm-codegen to generate bindings for this module with elm-codegen install app/ (so it gives me Gen.Effect).

It generates this definition:

none : Elm.Expression
none =
    Elm.value
        { importFrom = [ "Effect" ]
        , name = "none"
        , annotation = Just (Type.namedWith [] "Effect" [ Type.var "msg" ])

Which results in

import Effect

update : -- ...
    -> ( Model, Effect msg ) -- should be `Effect.Effect msg` (or import alias)

If I tweak this in the generated code, it results in correct, compiling output:

module Gen.Effect exposing -- ...

none : Elm.Expression
none =
    Elm.value
        { importFrom = [ "Effect" ]
        , name = "none"
        , annotation = Just (Type.namedWith [ "Effect" ] "Effect" [ Type.var "msg" ])
        }

I'm not sure if using Type.namedWith [ "Effect" ] "Effect" is the right fix, or if it should be using importFrom to get the right namespace there, but seems like it's one of those things I believe.

There's a reproducible case for this if you clone this repo and run these two commands: https://github.com/dillonkearns/elm-pages-3-alpha-starter#running-elm-pages-codegen-command, and then look at the resulting output file app/Route/User/Id_.elm.

Let me know if there's any other context I can provide here. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions