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

Dart: do not generate redundant import for external constants #1640

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Gluecodium project Release Notes

## Unreleased
### Bug fixes:
* Dart: removed generation of redundant import for constants declared with external types. The redundant import caused linter warnings.

## 13.10.1
Release date 2024-12-12
### Bug fixes:
Expand Down
6 changes: 6 additions & 0 deletions functional-tests/functional/input/lime/DartExternalTypes.lime
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ struct VeryBoolean {
value: Boolean
constructor make(value: Boolean)
}

@Java(Skip) @Swift(Skip)
struct ExternalDartConstants {
const Small: Rectangle = {0, 0, 1, 1}
const Big: Rectangle = {0, 0, 10, 10}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class DartImportResolver(
resolveTypeImports(limeElement.type) + resolveConversionImports(limeElement) +
listOfNotNull(lazyListImport.takeIf { limeElement.attributes.have(LimeAttributeType.OPTIMIZED) })
is LimeType -> resolveTypeImports(limeElement) + resolveConversionImports(limeElement)
is LimeConstant -> resolveTypeImports(limeElement.typeRef.type)
is LimeConstant -> resolveTypeImports(limeElement.typeRef.type, skipHelpers = true)
is LimeValue -> resolveValueImports(limeElement)
is LimeNamedElement -> listOf(createImport(limeElement))
else -> emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ struct DartExternalCtor {
`field`: String
constructor make(`field`: String)
}

@Java(Skip) @Swift(Skip)
struct ExternalDartConstants {
const Small: Rectangle = {0, 0, 1, 1}
const Big: Rectangle = {0, 0, 10, 10}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@


import 'dart:ffi';
import 'dart:math' as math;
import 'package:library/src/_library_context.dart' as __lib;


class ExternalDartConstants {
static final math.Rectangle<int> small = math.Rectangle<int>(0, 0, 1, 1);

static final math.Rectangle<int> big = math.Rectangle<int>(0, 0, 10, 10);

}


// ExternalDartConstants "private" section, not exported.

final _smokeExternaldartconstantsCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(),
Pointer<Void> Function()
>('library_smoke_ExternalDartConstants_create_handle'));
final _smokeExternaldartconstantsReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_ExternalDartConstants_release_handle'));



Pointer<Void> smokeExternaldartconstantsToFfi(ExternalDartConstants value) {
final _result = _smokeExternaldartconstantsCreateHandle();
return _result;
}

ExternalDartConstants smokeExternaldartconstantsFromFfi(Pointer<Void> handle) {
try {
return ExternalDartConstants(
);
} finally {
}
}

void smokeExternaldartconstantsReleaseFfiHandle(Pointer<Void> handle) => _smokeExternaldartconstantsReleaseHandle(handle);

// Nullable ExternalDartConstants

final _smokeExternaldartconstantsCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_ExternalDartConstants_create_handle_nullable'));
final _smokeExternaldartconstantsReleaseHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
void Function(Pointer<Void>)
>('library_smoke_ExternalDartConstants_release_handle_nullable'));
final _smokeExternaldartconstantsGetValueNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Pointer<Void>),
Pointer<Void> Function(Pointer<Void>)
>('library_smoke_ExternalDartConstants_get_value_nullable'));

Pointer<Void> smokeExternaldartconstantsToFfiNullable(ExternalDartConstants? value) {
if (value == null) return Pointer<Void>.fromAddress(0);
final _handle = smokeExternaldartconstantsToFfi(value);
final result = _smokeExternaldartconstantsCreateHandleNullable(_handle);
smokeExternaldartconstantsReleaseFfiHandle(_handle);
return result;
}

ExternalDartConstants? smokeExternaldartconstantsFromFfiNullable(Pointer<Void> handle) {
if (handle.address == 0) return null;
final _handle = _smokeExternaldartconstantsGetValueNullable(handle);
final result = smokeExternaldartconstantsFromFfi(_handle);
smokeExternaldartconstantsReleaseFfiHandle(_handle);
return result;
}

void smokeExternaldartconstantsReleaseFfiHandleNullable(Pointer<Void> handle) =>
_smokeExternaldartconstantsReleaseHandleNullable(handle);

// End of ExternalDartConstants "private" section.


Loading