Skip to content

Field with the same name as a type results in "unresolvable field type" #569

@codeka

Description

@codeka

protobuf.js version: v6.2.1

A field in a message with the same name as a type should be allowed (it works in Google's protocol buffer compiler and also in protobufjs versions 5 and earlier).

syntax = "proto3";

message A {
  string whatever = 1;
}

message B {
  A A = 1;
}

Compile with:

pbjs --target static *.proto

Results in:

.../node_modules/protobufjs/cli/pbjs.js:134
                    throw err;
                    ^

Error: unresolvable field type: A
    at Field.resolve (.../node_modules/protobufjs/src/field.js:248:19)
    at .../node_modules/protobufjs/cli/targets/static.js:184:15
    at Array.forEach (native)
    at buildType (.../node_modules/protobufjs/cli/targets/static.js:183:22)
    at buildNamespace (.../node_modules/protobufjs/cli/targets/static.js:96:9)
    at .../node_modules/protobufjs/cli/targets/static.js:113:13
    at Array.forEach (native)
    at buildNamespace (.../node_modules/protobufjs/cli/targets/static.js:109:20)
    at static_target (.../node_modules/protobufjs/cli/targets/static.js:28:9)
    at .../node_modules/protobufjs/cli/pbjs.js:129:9

(Note --target json works, but if you use the subsequent .json file to generate a static module it fails with the same error. I haven't tried importing the .json file directly though).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions