Skip to content

Conversation

@fa0311
Copy link
Contributor

@fa0311 fa0311 commented Mar 4, 2025

We will stop using OneOfDynamic and switch to OneOfx.
This will improve type safety.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)

@fa0311 fa0311 changed the title test [dart][dart-dio] Add type information to oneOf and anyOf Mar 4, 2025
@fa0311 fa0311 marked this pull request as draft March 4, 2025 18:27
@fa0311 fa0311 marked this pull request as ready for review March 4, 2025 20:26
@fa0311
Copy link
Contributor Author

fa0311 commented Mar 4, 2025

Unfortunately, the dart-dio generator seems to lack sufficient tests, so it's unclear whether it works correctly in all cases.
In my case, it works fine.

Copy link
Contributor

@ahmednfwela ahmednfwela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this case just return OneOfDynamic to be backwards compatible?

typeIndex: oneOf.typeIndex,
);
}
throw ArgumentError('Invalid number of types: ${oneOf.types.length}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meant here

Copy link
Contributor Author

@fa0311 fa0311 Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can maintain backward compatibility, but a simple replacement won't work.
If we simply return OneOfDynamic, it will fail when casting to OneOfx (OneOf{{oneOf.size}}), resulting in an error.
A slightly more involved approach would be to introduce a flag for cases with seven or more oneof values—if set to true, it would use OneOfDynamic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I never really liked the idea of fitting infinitely large oneof/anyof cases into a single variable

The approach I followed here #18970 is much cleaner, and is similar to what protobuf does

@EduMenges
Copy link
Contributor

Any updates?

@fa0311
Copy link
Contributor Author

fa0311 commented Aug 5, 2025

There are no updates to this.
Is there a better way?

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.

3 participants