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

wasm_wit_component generated code does not compile #58

Open
thejobsmarket opened this issue Jun 12, 2024 · 0 comments
Open

wasm_wit_component generated code does not compile #58

thejobsmarket opened this issue Jun 12, 2024 · 0 comments

Comments

@thejobsmarket
Copy link

Here is the wit file
package mypackage:plugin

/// An example world for the component to target.
world plugin {
export widget-name: func() -> result<string, string>
export widget-code: func() -> result<string, string>
export request: func(key: string, config: string) -> result<string, string>
}

Below is the fully generated file. However everywhere where there is a FuncType, e.g.
const FuncType([], [('', ResultType(StringType(), StringType()))]),
You get the following error:
The element type 'String' can't be assigned to the list type '(String, ValType)'.

// FILE GENERATED FROM WIT

// ignore: lines_longer_than_80_chars
// ignore_for_file: require_trailing_commas, unnecessary_raw_strings, unnecessary_non_null_assertion, unused_element, avoid_returning_null_for_void

import 'dart:async';
// ignore: unused_import
import 'dart:typed_data';

import 'package:wasm_wit_component/wasm_wit_component.dart';

class PluginWorldImports {
const PluginWorldImports();
}

/// An example world for the component to target.
class PluginWorld {
final PluginWorldImports imports;
final WasmLibrary library;

PluginWorld({
required this.imports,
required this.library,
}) : _widgetName = library.getComponentFunction(
'widget-name',
const FuncType([], [('', ResultType(StringType(), StringType()))]),
)!,
_widgetCode = library.getComponentFunction(
'widget-code',
const FuncType([], [('', ResultType(StringType(), StringType()))]),
)!,
_request = library.getComponentFunction(
'request',
const FuncType([
('key', StringType()),
('config', StringType())
], [
('', ResultType(StringType(), StringType()))
]),
)!;

static Future init(
WasmInstanceBuilder builder, {
required PluginWorldImports imports,
}) async {
late final WasmLibrary library;
WasmLibrary getLib() => library;

final instance = await builder.build();

library = WasmLibrary(instance,
    componentId: 'mypackage:plugin/plugin',
    int64Type: Int64TypeConfig.bigInt);
return PluginWorld(imports: imports, library: library);

}

static final _zoneKey = Object();
late final _zoneValues = {_zoneKey: this};
static PluginWorld? currentZoneWorld() =>
Zone.current[_zoneKey] as PluginWorld?;
T withContext(T Function() fn) => runZoned(fn, zoneValues: _zoneValues);

final ListValue Function(ListValue) _widgetName;
Result<String, String> widgetName() {
final results = _widgetName([]);
final result = results[0];
return withContext(() => Result.fromJson(
result,
(ok) => ok is String ? ok : (ok! as ParsedString).value,
(error) => error is String ? error : (error! as ParsedString).value));
}

final ListValue Function(ListValue) _widgetCode;
Result<String, String> widgetCode() {
final results = _widgetCode([]);
final result = results[0];
return withContext(() => Result.fromJson(
result,
(ok) => ok is String ? ok : (ok! as ParsedString).value,
(error) => error is String ? error : (error! as ParsedString).value));
}

final ListValue Function(ListValue) _request;
Result<String, String> request({
required String key,
required String config,
}) {
final results = _request([key, config]);
final result = results[0];
return withContext(() => Result.fromJson(
result,
(ok) => ok is String ? ok : (ok! as ParsedString).value,
(error) => error is String ? error : (error! as ParsedString).value));
}
}

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

No branches or pull requests

1 participant