Skip to content
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

Fix ref type generation for constructor invocation in dart. #1538

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Bug fixes:
* Fixed documentation references to constructors in Java.
* Added forward declaration for inner interfaces and classes.
* Fixed Dart code generation for struct initialization.

## 13.6.1
### Bug fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal class DartNameResolver(
else -> resolveName(noFieldsConstructor).let { if (it.isEmpty()) "" else ".$it" }
}
limeValue.values.joinToString(
prefix = "${resolveName(limeValue.typeRef)}$constructorName(",
prefix = "${resolveTypeRefName(limeValue.typeRef, ignoreNullability = true)}$constructorName(",
postfix = ")",
separator = ", "
) { resolveValue(it) }
Expand Down Expand Up @@ -259,7 +259,11 @@ internal class DartNameResolver(
return "${resolveFullName(parentElement)}.$ownName"
}

private fun resolveTypeRefName(limeTypeRef: LimeTypeRef, ignoreDuplicates: Boolean = false): String {
private fun resolveTypeRefName(
limeTypeRef: LimeTypeRef,
ignoreDuplicates: Boolean = false,
ignoreNullability: Boolean = false
): String {
val typeName = resolveName(limeTypeRef.type)
val importPath = limeTypeRef.type.actualType.external?.dart?.get(IMPORT_PATH_NAME)
val alias = when {
Expand All @@ -268,7 +272,7 @@ internal class DartNameResolver(
duplicateNames.contains(typeName) -> limeTypeRef.type.actualType.path.head.joinToString("_")
else -> null
}
val suffix = if (limeTypeRef.isNullable) "?" else ""
val suffix = if (limeTypeRef.isNullable && !ignoreNullability) "?" else ""
return listOfNotNull(alias, typeName).joinToString(".") + suffix
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,20 @@ struct FieldConstructorsParameterDefaults {
@Swift(ParameterDefaults)
field constructor(stringField, intField, boolField)
}

@Skip(Java, Swift)
struct FieldConstructorsNullableTypes {
enum FoodType {
VEGETABLES,
FRUITS
}

struct StructWithParameters {
foodType: FoodType = FoodType.FRUITS

@Skip(Java, Swift)
field constructor(foodType)
}

nullableField: StructWithParameters? = {FoodType.FRUITS}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import 'dart:ffi';
import 'package:library/src/_library_context.dart' as __lib;

class FieldConstructorsNullableTypes {
FieldConstructorsNullableTypes_StructWithParameters? nullableField;

FieldConstructorsNullableTypes._(this.nullableField);
FieldConstructorsNullableTypes()
: nullableField = FieldConstructorsNullableTypes_StructWithParameters(FieldConstructorsNullableTypes_FoodType.fruits);
}

enum FieldConstructorsNullableTypes_FoodType {
vegetables,
fruits
}

// FieldConstructorsNullableTypes_FoodType "private" section, not exported.

int smokeFieldconstructorsnullabletypesFoodtypeToFfi(FieldConstructorsNullableTypes_FoodType value) {
switch (value) {
case FieldConstructorsNullableTypes_FoodType.vegetables:
return 0;
case FieldConstructorsNullableTypes_FoodType.fruits:
return 1;
default:
throw StateError("Invalid enum value $value for FieldConstructorsNullableTypes_FoodType enum.");
}
}

FieldConstructorsNullableTypes_FoodType smokeFieldconstructorsnullabletypesFoodtypeFromFfi(int handle) {
switch (handle) {
case 0:
return FieldConstructorsNullableTypes_FoodType.vegetables;
case 1:
return FieldConstructorsNullableTypes_FoodType.fruits;
default:
throw StateError("Invalid numeric value $handle for FieldConstructorsNullableTypes_FoodType enum.");
}
}

void smokeFieldconstructorsnullabletypesFoodtypeReleaseFfiHandle(int handle) {}

final _smokeFieldconstructorsnullabletypesFoodtypeCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Uint32),
Pointer<Void> Function(int)
>('library_smoke_FieldConstructorsNullableTypes_FoodType_create_handle_nullable'));
final _smokeFieldconstructorsnullabletypesFoodtypeReleaseHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_FoodType_release_handle_nullable'));
final _smokeFieldconstructorsnullabletypesFoodtypeGetValueNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_FoodType_get_value_nullable'));

Pointer<Void> smokeFieldconstructorsnullabletypesFoodtypeToFfiNullable(FieldConstructorsNullableTypes_FoodType? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeFieldconstructorsnullabletypesFoodtypeToFfi(value);
final result = _smokeFieldconstructorsnullabletypesFoodtypeCreateHandleNullable(_handle);
smokeFieldconstructorsnullabletypesFoodtypeReleaseFfiHandle(_handle);
return result;
}

FieldConstructorsNullableTypes_FoodType? smokeFieldconstructorsnullabletypesFoodtypeFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeFieldconstructorsnullabletypesFoodtypeGetValueNullable(handle);
final result = smokeFieldconstructorsnullabletypesFoodtypeFromFfi(_handle);
smokeFieldconstructorsnullabletypesFoodtypeReleaseFfiHandle(_handle);
return result;
}

void smokeFieldconstructorsnullabletypesFoodtypeReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeFieldconstructorsnullabletypesFoodtypeReleaseHandleNullable(handle);

// End of FieldConstructorsNullableTypes_FoodType "private" section.

class FieldConstructorsNullableTypes_StructWithParameters {
FieldConstructorsNullableTypes_FoodType foodType;

FieldConstructorsNullableTypes_StructWithParameters(this.foodType);
}


// FieldConstructorsNullableTypes_StructWithParameters "private" section, not exported.

final _smokeFieldconstructorsnullabletypesStructwithparametersCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Uint32),
Pointer<Void> Function(int)
>('library_smoke_FieldConstructorsNullableTypes_StructWithParameters_create_handle'));
final _smokeFieldconstructorsnullabletypesStructwithparametersReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_StructWithParameters_release_handle'));
final _smokeFieldconstructorsnullabletypesStructwithparametersGetFieldfoodType = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint32 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_StructWithParameters_get_field_foodType'));



Pointer<Void> smokeFieldconstructorsnullabletypesStructwithparametersToFfi(FieldConstructorsNullableTypes_StructWithParameters value) {
final _foodTypeHandle = smokeFieldconstructorsnullabletypesFoodtypeToFfi(value.foodType);
final _result = _smokeFieldconstructorsnullabletypesStructwithparametersCreateHandle(_foodTypeHandle);
smokeFieldconstructorsnullabletypesFoodtypeReleaseFfiHandle(_foodTypeHandle);
return _result;
}

FieldConstructorsNullableTypes_StructWithParameters smokeFieldconstructorsnullabletypesStructwithparametersFromFfi(Pointer<Void> handle) {
final _foodTypeHandle = _smokeFieldconstructorsnullabletypesStructwithparametersGetFieldfoodType(handle);
try {
return FieldConstructorsNullableTypes_StructWithParameters(
smokeFieldconstructorsnullabletypesFoodtypeFromFfi(_foodTypeHandle)
);
} finally {
smokeFieldconstructorsnullabletypesFoodtypeReleaseFfiHandle(_foodTypeHandle);
}
}

void smokeFieldconstructorsnullabletypesStructwithparametersReleaseFfiHandle(Pointer<Void> handle) => _smokeFieldconstructorsnullabletypesStructwithparametersReleaseHandle(handle);

// Nullable FieldConstructorsNullableTypes_StructWithParameters

final _smokeFieldconstructorsnullabletypesStructwithparametersCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_StructWithParameters_create_handle_nullable'));
final _smokeFieldconstructorsnullabletypesStructwithparametersReleaseHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_StructWithParameters_release_handle_nullable'));
final _smokeFieldconstructorsnullabletypesStructwithparametersGetValueNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_StructWithParameters_get_value_nullable'));

Pointer<Void> smokeFieldconstructorsnullabletypesStructwithparametersToFfiNullable(FieldConstructorsNullableTypes_StructWithParameters? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeFieldconstructorsnullabletypesStructwithparametersToFfi(value);
final result = _smokeFieldconstructorsnullabletypesStructwithparametersCreateHandleNullable(_handle);
smokeFieldconstructorsnullabletypesStructwithparametersReleaseFfiHandle(_handle);
return result;
}

FieldConstructorsNullableTypes_StructWithParameters? smokeFieldconstructorsnullabletypesStructwithparametersFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeFieldconstructorsnullabletypesStructwithparametersGetValueNullable(handle);
final result = smokeFieldconstructorsnullabletypesStructwithparametersFromFfi(_handle);
smokeFieldconstructorsnullabletypesStructwithparametersReleaseFfiHandle(_handle);
return result;
}

void smokeFieldconstructorsnullabletypesStructwithparametersReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeFieldconstructorsnullabletypesStructwithparametersReleaseHandleNullable(handle);

// End of FieldConstructorsNullableTypes_StructWithParameters "private" section.

// FieldConstructorsNullableTypes "private" section, not exported.

final _smokeFieldconstructorsnullabletypesCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_create_handle'));
final _smokeFieldconstructorsnullabletypesReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_release_handle'));
final _smokeFieldconstructorsnullabletypesGetFieldnullableField = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_get_field_nullableField'));



Pointer<Void> smokeFieldconstructorsnullabletypesToFfi(FieldConstructorsNullableTypes value) {
final _nullableFieldHandle = smokeFieldconstructorsnullabletypesStructwithparametersToFfiNullable(value.nullableField);
final _result = _smokeFieldconstructorsnullabletypesCreateHandle(_nullableFieldHandle);
smokeFieldconstructorsnullabletypesStructwithparametersReleaseFfiHandleNullable(_nullableFieldHandle);
return _result;
}

FieldConstructorsNullableTypes smokeFieldconstructorsnullabletypesFromFfi(Pointer<Void> handle) {
final _nullableFieldHandle = _smokeFieldconstructorsnullabletypesGetFieldnullableField(handle);
try {
return FieldConstructorsNullableTypes._(
smokeFieldconstructorsnullabletypesStructwithparametersFromFfiNullable(_nullableFieldHandle)
);
} finally {
smokeFieldconstructorsnullabletypesStructwithparametersReleaseFfiHandleNullable(_nullableFieldHandle);
}
}

void smokeFieldconstructorsnullabletypesReleaseFfiHandle(Pointer<Void> handle) => _smokeFieldconstructorsnullabletypesReleaseHandle(handle);

// Nullable FieldConstructorsNullableTypes

final _smokeFieldconstructorsnullabletypesCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_create_handle_nullable'));
final _smokeFieldconstructorsnullabletypesReleaseHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_release_handle_nullable'));
final _smokeFieldconstructorsnullabletypesGetValueNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_FieldConstructorsNullableTypes_get_value_nullable'));

Pointer<Void> smokeFieldconstructorsnullabletypesToFfiNullable(FieldConstructorsNullableTypes? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeFieldconstructorsnullabletypesToFfi(value);
final result = _smokeFieldconstructorsnullabletypesCreateHandleNullable(_handle);
smokeFieldconstructorsnullabletypesReleaseFfiHandle(_handle);
return result;
}

FieldConstructorsNullableTypes? smokeFieldconstructorsnullabletypesFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeFieldconstructorsnullabletypesGetValueNullable(handle);
final result = smokeFieldconstructorsnullabletypesFromFfi(_handle);
smokeFieldconstructorsnullabletypesReleaseFfiHandle(_handle);
return result;
}

void smokeFieldconstructorsnullabletypesReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeFieldconstructorsnullabletypesReleaseHandleNullable(handle);

// End of FieldConstructorsNullableTypes "private" section.