Skip to content

Conversation

@kuhnroyal
Copy link
Contributor

  • leading underscores _ mark private fields in Dart, so until now we just removed them
  • but just removing the fields can lead to name collision and missing fields
  • a prominent use-case are fields id and _id which previously would result in the _id field being lost on the Dart side
  • fixes [BUG] [dart-dio] _id is generated as id #14482

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 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date.sh
    
    Commit all changed files.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.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.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still have potential collisions here and we also loose double (multiple) underscores due to the implementation of the camelize method. But I am not sure it is worth to rewrite it all.

@ahmednfwela
Copy link
Contributor

how about transforming _fieldName to $_fieldName, it keeps the underscore and prevents collisions and since it doesn't start with _ it's not private
so _id would become $_id
however this generates lint warning non_constant_identifier_names
image

@kuhnroyal
Copy link
Contributor Author

how about transforming _fieldName to $_fieldName, it keeps the underscore and prevents collisions and since it doesn't start with _ it's not private so _id would become $_id however this generates lint warning non_constant_identifier_names image

Yea was wondering the same, not sure what happens with built_value then because it also prefixes all kinds of things with $.

@kuhnroyal
Copy link
Contributor Author

We also convert $ to dollar

@ahmednfwela
Copy link
Contributor

built value only prefixes class names with $, but it's a valid identifier to use.
also I don't know why $ gets transformed to "dollarsign" maybe we remove it in next major release

@kuhnroyal
Copy link
Contributor Author

built value only prefixes class names with $, but it's a valid identifier to use. also I don't know why $ gets transformed to "dollarsign" maybe we remove it in next major release

Yea it probably is like that since the dawn of time because the generator just used the the Java way of things.

I am not sure how to proceed, any change, even the current one is breaking some cases but on the other hand it is also a bug...

* leading underscores `_` mark private fields in Dart, so until now we just removed them
* but just removing the fields can lead to name collision and missing fields
* a prominent use-case are fields `id` and `_id` which previously would result in the `_id` field being lost on the Dart side
@kuhnroyal kuhnroyal force-pushed the dart-dio/identifiers branch from 1c34fe9 to ed376e2 Compare February 15, 2023 18:13
@ahmednfwela
Copy link
Contributor

well, my suggestion is that if we are going to break anyway, lets do it right
$ should be enabled back and used to escape initial _

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.

[BUG] [dart-dio] _id is generated as id

2 participants