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

protoc: inconsistent name resolution behavior #6296

Closed
dsnet opened this issue Jun 21, 2019 · 6 comments
Closed

protoc: inconsistent name resolution behavior #6296

dsnet opened this issue Jun 21, 2019 · 6 comments
Labels
bug inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc

Comments

@dsnet
Copy link
Contributor

dsnet commented Jun 21, 2019

Consider the following proto file:

package foo.bar;
message M {    // declared as .foo.bar.M
    enum E {   // declared as .foo.bar.M.E
        M = 0; // declared as .foo.bar.M.M
    }
    optional M F1 = 1;
    extend M { optional string F2 = 2; }
    extensions 2 to 2;
}

There are two relative M references:

  • optional M ...
  • extend M { ... }

Both relative M references occur within the .foo.bar.M namespace.

Per the C++ scoping rules, the following absolute names should be tried in the following order:

  • .foo.bar.M.M
  • .foo.bar.M
  • .foo.M
  • .M

In our situation, both .foo.bar.M.M and .foo.bar.M are legal declarations.

However, the way resolution is handled is odd:

  • For the case of optional M ..., it first finds .foo.bar.M.M, which is an enum value type. Since it's looking for an enum or message type, it ignore this. It continues on to then find .foo.bar.M. Since this is a message type, it returns that declaration.
  • For the case of extend M ..., it first finds .foo.bar.M.M, which is an enum value type. Since it's looking for a message type, it throws an error complaining that it found the wrong type.

This is inconsistent. The relative name resolution logic should either:

  • always ignore the declaration of the wrong type and keep searching
  • always error when finding a declaration of the wrong type

What is the right behavior?

@ghost
Copy link

ghost commented Jun 26, 2019

"always error when finding a declaration of the wrong type" seems like the more desirable behavior. At the minimum, it would highlight that there are some confusing types there, instead of magically resolve to some random type.

If we make it to always error, how many things will break?

@BSBandme BSBandme assigned ghost Jul 1, 2019
@ghost ghost removed their assignment Jul 19, 2019
@jhump
Copy link
Contributor

jhump commented Aug 19, 2022

FWIW, method input and output names behave the same as extendee -- resolution of these names does not skip over non-type elements as is done for field types.

@jhump
Copy link
Contributor

jhump commented Aug 19, 2022

Same goes for extension name resolution, when resolving option names. Though there is no "ResolveMode" that would work for this (i.e. there is no "LOOKUP_EXTENSIONS" value).

@jhump
Copy link
Contributor

jhump commented Aug 19, 2022

This is sort of related to #9550. Different root cause and symptom, but also about inconsistent behavior when it comes to resolving names from different contexts.

Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Apr 14, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc
Projects
None yet
Development

No branches or pull requests

3 participants