wasm_run icon indicating copy to clipboard operation
wasm_run copied to clipboard

wasm_wit_component generated code does not compile

Open thejobsmarket opened this issue 8 months ago • 0 comments

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<PluginWorld> 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>(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)); } }

thejobsmarket avatar Jun 12 '24 15:06 thejobsmarket