Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Error: Field name same as Message/Enum Name #57

Closed
chasewalden opened this issue Apr 3, 2024 · 2 comments · Fixed by #58
Closed

Parse Error: Field name same as Message/Enum Name #57

chasewalden opened this issue Apr 3, 2024 · 2 comments · Fixed by #58

Comments

@chasewalden
Copy link

Summary

There appears to be a bug in the parser. If a field name is identical to a message/enum name, the parsing fails. The official protoc compiler does not fail on this.

I am trying to compile moby/buildkit/solver/pb/ops.proto, but protox fails on some of the fields.

Expected Behavior:

protox compiler has parity with official protoc compiler. Field names can be any valid identifier, including other message/enum type names.

Actual Behavior:

protox fails to compile fields that have identical names as defined message/enum types.

Minimal Reproduction Case:

protos/minimal.proto

syntax = "proto3";

message Parent {
    ChildMessage ChildMessage  = 1;
    ChildEnum ChildEnum  = 2;
}

message ChildMessage {
    string field = 1;
}

enum ChildEnum {
    UNKNOWN = 0;
    A = 1;
    B = 2;
}

build.rs

fn main() -> miette::Result<()> {
    let _ = protox::compile(
        ["protos/minimal.proto"],
        ["protos/"],
    )?;

    // ...

    Ok(())
}

Output

❯ cargo b
# ...
error: failed to run custom build command for `...` (exit status: 1)

Caused by: 
  process didn't exit successfully: ... (exit status: 1)
  --- stderr
  Error:   × 'ChildMessage' is not a message or enum type
     ╭─[min.proto:4:5]
   3 │ message Parent {
   4 │     ChildMessage ChildMessage  = 1;
     ·     ──────┬───── ──────┬─────
     ·           │            ╰── defined here
     ·           ╰── found here
   5 │     ChildEnum ChildEnum  = 2;
     ╰────

  Error:   × 'ChildEnum' is not a message or enum type
     ╭─[min.proto:5:5]
   4 │     ChildMessage ChildMessage  = 1;
   5 │     ChildEnum ChildEnum  = 2;
     ·     ────┬──── ────┬────
     ·         │         ╰── defined here
     ·         ╰── found here
   6 │ }
     ╰────

I have not been able to find where the particular diagnostic is being generated from, but will file a PR if I can find and fix.

@andrewhickman
Copy link
Owner

Thanks for the report, this should be fixed by andrewhickman/prost-reflect#100 in prost-reflect version 0.13.1

@chasewalden
Copy link
Author

Wow. That was an insanely quick turnaround. Thanks for closing this too. I meant to backlink the other ticket, but it must have slipped my mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants