Skip to content

fix(dart): hide internal fields in ctor#1809

Open
isidorowiczdev wants to merge 2 commits into
heremaps:masterfrom
isidorowiczdev:ctor-fix
Open

fix(dart): hide internal fields in ctor#1809
isidorowiczdev wants to merge 2 commits into
heremaps:masterfrom
isidorowiczdev:ctor-fix

Conversation

@isidorowiczdev

Copy link
Copy Markdown
Contributor

Fix Dart generator so internal fields stay out of public all-args constructor. Reason: current generator leaks @internal field into public API, unlike Java, and smoke tests show broken output.

Signed-off-by: Iwo Sidorowicz <294463459+isidorowiczdev@users.noreply.github.com>
@pwrobeldev

Copy link
Copy Markdown
Contributor

As discussed offline -- besides the problem with all args ctor there seems to also be a problem when we have at least 1 initialized field in the structure.

Please have a look at the following input from our smoke tests:

And the corresponding output for Dart:

In the output file you can see that all args ctor is private, but initialized fields ctor that is public exposes the internal field and takes its value -- this does not seem correct.

@Hsilgos

Hsilgos commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Hide whole constructor because of one field?
May be filter it out like fields with default values?

!useDefaultsConstructor -> ""
noFieldsConstructor == null ->
if (DartGeneratorPredicates.allFieldsCtorIsPublic(actualType)) ".withDefaults" else ""
if (DartGeneratorPredicates.allFieldsCtorIsPublic(actualType)) ".withDefaults" else "._withDefaults"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unfortunately, this breaks the functional tests. They do not compile. We need to analyze the logic of generation constructors, because the fix may not be trivial.

@pwrobeldev

Copy link
Copy Markdown
Contributor

Hide whole constructor because of one field? May be filter it out like fields with default values?

@Hsilgos -- is the proposal to filter the internal field from the constructor's parameters list?

If that's the proposal, then I have one question:

  • How will that field be initialized if it does not have default value set?

If I understand correctly, if we filtered such field from the constructor then it would be uninitialized.

…nal fields

Signed-off-by: Iwo Sidorowicz <294463459+isidorowiczdev@users.noreply.github.com>
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