tiziano88 / elm-protobuf

protobuf plugin for elm
https://package.elm-lang.org/packages/tiziano88/elm-protobuf/latest/
MIT License
94 stars 28 forks source link

Incorrect code generated with type names #28

Open mharmer opened 5 years ago

mharmer commented 5 years ago

When compiling a single proto file that imports another, the referenced types don't seem to be correct:

sub.proto:

syntax = "proto3";

package Foo;

message Baz2 {
    int32 field_a = 1;
}

main.proto:

syntax = "proto3";

import "sub.proto";

package Foo;

message Baz {
    Baz2 field_a = 1;
}

Compiled with: protoc --elm_out=. main.proto sub.proto

Produces incorrect code:

-- Sub.elm
type alias Baz2 =
    { fieldA : Int -- 1
    }

-- Main.elm
type alias Baz =
    { fieldA : Maybe Foo_Baz2 -- 1
    }

Compiler error for reference:

I cannot find a `Foo_Baz2` type:

16|     { fieldA : Maybe Foo_Baz2 -- 1

It seems as though the package name is incorrectly being added to the name of the type. As a workaround, if I comment out the package name from both proto files it seems to generate correct code.

I don't know if this falls into the unsupported 'Packages' listing in the main README.md, since it didn't list details as to why it wasn't supported.

Interestingly, this is very similar to a bug I just reported in the other Elm protoc project: https://github.com/eriktim/protoc-gen-elm/issues/7