Skip to content

Lack of edition_defaults support #112

@webmaster128

Description

@webmaster128

When updating proto files to latest, we get an update in google/protobuf/descriptor.proto (not sure here that comes from). This leads to the folloing compilation error:

npm run build

> [email protected] build
> rm -rf ./build && tsc && npm run prepare-publishing

src/google/protobuf/descriptor.ts:4655:5 - error TS2322: Type '1' is not assignable to type 'FeatureSet_Utf8Validation'.

4655     utf8Validation: 1,
         ~~~~~~~~~~~~~~

  src/google/protobuf/descriptor.ts:1689:3
    1689   utf8Validation: FeatureSet_Utf8Validation;
           ~~~~~~~~~~~~~~
    The expected type comes from property 'utf8Validation' which is declared here on type 'FeatureSet'

src/google/protobuf/descriptor.ts:4673:9 - error TS2367: This comparison appears to be unintentional because the types 'FeatureSet_Utf8Validation' and '1' have no overlap.

4673     if (message.utf8Validation !== 1) {
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/google/protobuf/descriptor.ts:4759:5 - error TS2322: Type '1 | FeatureSet_Utf8Validation' is not assignable to type 'FeatureSet_Utf8Validation'.
  Type '1' is not assignable to type 'FeatureSet_Utf8Validation'.

4759     message.utf8Validation = object.utf8Validation ?? 1;
         ~~~~~~~~~~~~~~~~~~~~~~


Found 3 errors in the same file, starting at: src/google/protobuf/descriptor.ts:4655

The reason is the use of edition_defaults in

  enum Utf8Validation {
    UTF8_VALIDATION_UNKNOWN = 0;
    VERIFY = 2;
    NONE = 3;
    reserved 1;
  }
  optional Utf8Validation utf8_validation = 4 [
    retention = RETENTION_RUNTIME,
    targets = TARGET_TYPE_FIELD,
    targets = TARGET_TYPE_FILE,
    feature_support = {
      edition_introduced: EDITION_2023,
    },
    edition_defaults = { edition: EDITION_LEGACY, value: "NONE" },
    edition_defaults = { edition: EDITION_PROTO3, value: "VERIFY" }
  ];

For some reason, Telescope generates the code message.utf8Validation = object.utf8Validation ?? 1; but 1 is the wrong default value. In fact the value 1 does not exist in enum Utf8Validation.

I think we need to teach Telescope how to correctly interpret edition_defaults annotations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions