Fix extension validation for proto2 required fields#746
Conversation
| } else { | ||
| d.Apply(report.Snippet(m.AST())) | ||
| } | ||
| d.Apply(report.Helpf("extensions cannot use the `required` label")) |
There was a problem hiding this comment.
label the right term here, what about a test for LEGACY_REQUIRED? extensions can't be required. would maybe fit both patterns better.
There was a problem hiding this comment.
The LEGACY_REQUIRED goes through the features, so the output you get is:
expected singular field, found extension
Which is basically the unexpected error... I had considered making them as similar as possible, in terms of the diagnostics, but I wasn't sure if that made sense in this case? So I just kind of kept them as separate diagnostics...
There was a problem hiding this comment.
Would be nicer to make it explicit.
There was a problem hiding this comment.
And as for the test case with LEGACY_REQUIRED -- I can add a test case, but proto2 files cannot set features, so it's not really a problem right now:
error: `features` cannot be set in "proto2"
--> testdata/extend/required.proto:16:33
|
1 | syntax = "proto2";
| -------- syntax specified here
...
16 | required string meow = 103 [features.field_presence = LEGACY_REQUIRED];
| ^^^^^^^^
error: `field_presence` is not supported in "proto2"
--> testdata/extend/required.proto:16:33
|
1 | syntax = "proto2";
| -------- syntax specified here
...
16 | required string meow = 103 [features.field_presence = LEGACY_REQUIRED];
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `field_presence` requires at least Edition 2023
There was a problem hiding this comment.
Would be nicer to make it explicit.
So the full diagnostic is explicit, it has help statement that says field_present cannot be set on extensions:
The output I provided is from buf, which currently doesn't use the full diagnostic report, so it doesn't appear to be explicit... but yeah...
| d.Apply(report.Snippet(required.PrefixToken())) | ||
| } else { | ||
| d.Apply(report.Snippet(m.AST())) |
There was a problem hiding this comment.
| d.Apply(report.Snippet(required.PrefixToken())) | |
| } else { | |
| d.Apply(report.Snippet(m.AST())) | |
| }); !required.IsZero() { | |
| d.Apply(report.Snippet(required.PrefixToken())) | |
| d.Apply(report.Helpf("extensions cannot use the `required` label")) | |
| } else { | |
| d.Apply(report.Snippet(m.AST())) | |
| d.Apply(report.Helpf("extensions cannot set `field_presence` to `LEGACY_REQUIRED`")) | |
| } |
There was a problem hiding this comment.
^ re: conversation in comment above, this is only checking for required field, and the features.field_presence is checked below with different diagnostics, so we shouldn't mix the diagnostics here.
This PR adds validation for non-editions features required
fields on extensions.