-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dart: enable custom fields with defaults that do not provide const constructor to work with 'PositionalDefaults' #1632
Open
pwrobeldev
wants to merge
10
commits into
master
Choose a base branch
from
pwrobeldev/mutable-custom-structs-defaults-for-positional-defaults
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pwrobeldev
changed the title
Dart: make custom structures that do not provide const constructor to work with 'PositionalDefaults'
Dart: enable custom fields with defaults that do not provide const constructor to work with 'PositionalDefaults'
Dec 2, 2024
pwrobeldev
force-pushed
the
pwrobeldev/mutable-custom-structs-defaults-for-positional-defaults
branch
from
December 2, 2024 09:53
92fe3d3
to
a7a2528
Compare
When the structure uses 'PositionalDefaults' annotation and fields that have default values, but do not provide const constructor (e.g. custom structures defined by the used, which are not 'Immutable'), then the generated code does not compile. This change showcases the invalid behavior. It adds smoke tests, which clearly show that 'const' keyword is added before constructor calls. Moreover, this commit introduces new LIME input for functional tests, which causes compilation errors. Signed-off-by: Patryk Wrobel <[email protected]>
This change introduces the fix for the bug showcased in the previous commit. In order to be able to generate code, which compiles when 'PositionalDefaults' annotation is used together with default values of structure types that do not provide const constructors, the optional values have been used. When Gluecodium encounters such type that does not provide const constructor it makes it optional in positional defaults constructor and uses null as default. Later, on initializer list it checks if user provided value different than null and if not, then initializes the field with the actual default value. This way the limitation related to const constructors is surpassed. However, if the user wants to have nullable type with default different than null, then the behavior may be surprising. Therefore, in next patches the required validation will be implemented for DartGenerator. Signed-off-by: Patryk Wrobel <[email protected]>
This commit introduces a new functional test, which verifies that the newly implemented logic in generator works as expected and non-const constructible struct default values are correct. Signed-off-by: Patryk Wrobel <[email protected]>
…aults This change introduces DartDefaultValuesValidator class which checks if the default value used for nullable custom structs, which do not provide const constructors are equal to 'null'. Signed-off-by: Patryk Wrobel <[email protected]>
This change extends the documentation of 'PositionalDefaults' annotation for Dart to describe the specific behavior in the case of nullable types. Signed-off-by: Patryk Wrobel <[email protected]>
The constructors of 'Uint8List' type are not const. This type is used when BLOB is specified in LIME file. Therefore, the usage of BLOB type for a field of struct that is marked as 'PositionalDefaults' and specifying a default value of this field leads to compilation error. This change is used to document the invalid behavior. Signed-off-by: Patryk Wrobel <[email protected]>
This change fixes the compilation error via using the same approach that was used for non-const constructible structures. This commit extends functional tests to confirm that BLOB can be used for a field with default value for structure annotated as 'PositionalDefaults'. Signed-off-by: Patryk Wrobel <[email protected]>
Disallow users from using nullable field of BLOB type that has default value different than null to avoid unexpected behavior. Signed-off-by: Patryk Wrobel <[email protected]>
This change includes the information about usage of nullable Blob field with default value in the structure annotated as 'PositionalDefaults'. Signed-off-by: Patryk Wrobel <[email protected]>
Signed-off-by: Patryk Wrobel <[email protected]>
pwrobeldev
force-pushed
the
pwrobeldev/mutable-custom-structs-defaults-for-positional-defaults
branch
from
December 13, 2024 06:43
cf32397
to
3438558
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
------ Motivation ------
When fields with default values were defined in a struct
and their types did not provide 'const' constructors, when
such fields were used in combination with 'PositionalDefaults',
then the generated code did not compile.
------ Designed solution ------
In order to be able to generate the code, which compiles
when 'PositionalDefaults' annotation is used together
with default values of types that do not provide const
constructors, the optional values have been used.
When Gluecodium encounters a type that does not
provide const constructor it makes it optional in
positional defaults constructor and uses null as
default.
Later, on initializer list it checks if user provided
value different than null and if not, then initializes
the field with the actual default value. This way
the limitation related to const constructors is surpassed.
However, if the user wants to have nullable type that
does not provide const constructor and uses default
value different than null, then the behavior may be surprising.
Therefore, the validator was implemented for Dart to prevent
users from such usage.
------ Contents of change ------