-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dart: fix problems with default values that use immutable types (#1623)
This series fixes problems that occur when either 'Immutable' or 'PositionalDefaults' annotation is used in combination with immutable types that have default value. In both cases the resulting code did not contain the required 'const' keyword. -------- Content of change -------- - New smoke and functional tests that were used to confirm the invalid behavior. - Adjustments of 'DartStructConstructors.mustache' file to correctly prepend 'const' keyword when needed for immutable struct fields. Signed-off-by: Patryk Wrobel <[email protected]>
- Loading branch information
1 parent
aa0f504
commit 92226b7
Showing
11 changed files
with
735 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
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
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
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
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
89 changes: 89 additions & 0 deletions
89
...aults/output/dart/lib/src/smoke/pos_default_struct_with_field_using_immutable_struct.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
|
||
import 'dart:ffi'; | ||
import 'package:library/src/_library_context.dart' as __lib; | ||
import 'package:library/src/smoke/immutable_struct_with_defaults.dart'; | ||
|
||
|
||
class PosDefaultStructWithFieldUsingImmutableStruct { | ||
ImmutableStructWithDefaults someField1; | ||
|
||
PosDefaultStructWithFieldUsingImmutableStruct([ImmutableStructWithDefaults someField1 = const ImmutableStructWithDefaults.withDefaults()]) | ||
: someField1 = someField1; | ||
} | ||
|
||
|
||
// PosDefaultStructWithFieldUsingImmutableStruct "private" section, not exported. | ||
|
||
final _smokePosdefaultstructwithfieldusingimmutablestructCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< | ||
Pointer<Void> Function(Pointer<Void>), | ||
Pointer<Void> Function(Pointer<Void>) | ||
>('library_smoke_PosDefaultStructWithFieldUsingImmutableStruct_create_handle')); | ||
final _smokePosdefaultstructwithfieldusingimmutablestructReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< | ||
Void Function(Pointer<Void>), | ||
void Function(Pointer<Void>) | ||
>('library_smoke_PosDefaultStructWithFieldUsingImmutableStruct_release_handle')); | ||
final _smokePosdefaultstructwithfieldusingimmutablestructGetFieldsomeField1 = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< | ||
Pointer<Void> Function(Pointer<Void>), | ||
Pointer<Void> Function(Pointer<Void>) | ||
>('library_smoke_PosDefaultStructWithFieldUsingImmutableStruct_get_field_someField1')); | ||
|
||
|
||
|
||
Pointer<Void> smokePosdefaultstructwithfieldusingimmutablestructToFfi(PosDefaultStructWithFieldUsingImmutableStruct value) { | ||
final _someField1Handle = smokeImmutablestructwithdefaultsToFfi(value.someField1); | ||
final _result = _smokePosdefaultstructwithfieldusingimmutablestructCreateHandle(_someField1Handle); | ||
smokeImmutablestructwithdefaultsReleaseFfiHandle(_someField1Handle); | ||
return _result; | ||
} | ||
|
||
PosDefaultStructWithFieldUsingImmutableStruct smokePosdefaultstructwithfieldusingimmutablestructFromFfi(Pointer<Void> handle) { | ||
final _someField1Handle = _smokePosdefaultstructwithfieldusingimmutablestructGetFieldsomeField1(handle); | ||
try { | ||
return PosDefaultStructWithFieldUsingImmutableStruct( | ||
smokeImmutablestructwithdefaultsFromFfi(_someField1Handle) | ||
); | ||
} finally { | ||
smokeImmutablestructwithdefaultsReleaseFfiHandle(_someField1Handle); | ||
} | ||
} | ||
|
||
void smokePosdefaultstructwithfieldusingimmutablestructReleaseFfiHandle(Pointer<Void> handle) => _smokePosdefaultstructwithfieldusingimmutablestructReleaseHandle(handle); | ||
|
||
// Nullable PosDefaultStructWithFieldUsingImmutableStruct | ||
|
||
final _smokePosdefaultstructwithfieldusingimmutablestructCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< | ||
Pointer<Void> Function(Pointer<Void>), | ||
Pointer<Void> Function(Pointer<Void>) | ||
>('library_smoke_PosDefaultStructWithFieldUsingImmutableStruct_create_handle_nullable')); | ||
final _smokePosdefaultstructwithfieldusingimmutablestructReleaseHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< | ||
Void Function(Pointer<Void>), | ||
void Function(Pointer<Void>) | ||
>('library_smoke_PosDefaultStructWithFieldUsingImmutableStruct_release_handle_nullable')); | ||
final _smokePosdefaultstructwithfieldusingimmutablestructGetValueNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< | ||
Pointer<Void> Function(Pointer<Void>), | ||
Pointer<Void> Function(Pointer<Void>) | ||
>('library_smoke_PosDefaultStructWithFieldUsingImmutableStruct_get_value_nullable')); | ||
|
||
Pointer<Void> smokePosdefaultstructwithfieldusingimmutablestructToFfiNullable(PosDefaultStructWithFieldUsingImmutableStruct? value) { | ||
if (value == null) return Pointer<Void>.fromAddress(0); | ||
final _handle = smokePosdefaultstructwithfieldusingimmutablestructToFfi(value); | ||
final result = _smokePosdefaultstructwithfieldusingimmutablestructCreateHandleNullable(_handle); | ||
smokePosdefaultstructwithfieldusingimmutablestructReleaseFfiHandle(_handle); | ||
return result; | ||
} | ||
|
||
PosDefaultStructWithFieldUsingImmutableStruct? smokePosdefaultstructwithfieldusingimmutablestructFromFfiNullable(Pointer<Void> handle) { | ||
if (handle.address == 0) return null; | ||
final _handle = _smokePosdefaultstructwithfieldusingimmutablestructGetValueNullable(handle); | ||
final result = smokePosdefaultstructwithfieldusingimmutablestructFromFfi(_handle); | ||
smokePosdefaultstructwithfieldusingimmutablestructReleaseFfiHandle(_handle); | ||
return result; | ||
} | ||
|
||
void smokePosdefaultstructwithfieldusingimmutablestructReleaseFfiHandleNullable(Pointer<Void> handle) => | ||
_smokePosdefaultstructwithfieldusingimmutablestructReleaseHandleNullable(handle); | ||
|
||
// End of PosDefaultStructWithFieldUsingImmutableStruct "private" section. | ||
|
||
|
Oops, something went wrong.