Skip to content

Reject empty statements in oneof and extend, and empty scalar arrays without colon - #811

Open
emcfarlane wants to merge 2 commits into
mainfrom
ed/emptyStatements
Open

emcfarlane wants to merge 2 commits into
mainfrom
ed/emptyStatements

Conversation

@emcfarlane

Copy link
Copy Markdown
Contributor

An empty ; is allowed at the top level and in message, enum, service, method and group bodies, but not in a oneof or extend block. The experimental compiler accepted it everywhere. Now reports it in those two blocks.

message M {
  oneof o {
    int32 a = 1;
    ;          // was: accepted
  }
}
extend M {
  ;            // was: accepted
}
option (foo) = {
  strs []      // was: warning only (strs is repeated string)
  foos []      // still accepted (foos is a message field)
};

In a message literal, the text format grammar lets a field leave out the : only if the field is message-typed:

MessageField = FieldName, [ ":" ], ( MessageValue | MessageList ) ...
ScalarField  = FieldName, ":", ( ScalarValue | ScalarList ) ...

So foos [] and foos [{}] are valid for a message field, but strs [] and strs ["x"] are not valid for a scalar one. The parser already rejected strs ["x"] by looking at the list's elements. An empty list has no elements to look at, so strs [] was accepted. The check needs the field's type. It now also runs during option evaluation so the type is known.

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 this pull request may close these issues.

1 participant