ethanblake4 / dart_eval

Extensible Dart interpreter for Dart with full interop
https://pub.dev/packages/dart_eval
BSD 3-Clause "New" or "Revised" License
334 stars 40 forks source link

type 'VariableDeclarationImpl' is not a subtype of type 'MethodDeclaration' in type cast #184

Open HXiaoMing opened 9 months ago

HXiaoMing commented 9 months ago

add a test in 'Bridge tests' at bridge_test.dart.

test('Using a subclassed bridge class with function', () {
      compiler.defineBridgeClasses([$TestClass.$declaration]);

      final program = compiler.compile({
        'example': {
          'main.dart': '''
            import 'package:bridge_lib/bridge_lib.dart';

            class MyTestClass extends TestClass {
              MyTestClass(int someNumber, this.testSum) : super(someNumber);

              final int Function(int num) testSum;

              @override
              bool runTest(int a, {String b = 'wow'}) {
                return super.runTest(a + 2 + someNumber, b: b);
              }
            }

            int main() {
              final test = MyTestClass(18, (num) {
                 return num + 1;
              });
              return test.testSum(1);
            }
          '''
        }
      });

      final runtime = Runtime.ofProgram(program);

      runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart',
          'TestClass.', $TestClass.$construct,
          isBridge: true);

      expect(runtime.executeLib('package:example/main.dart', 'main'), true);
    });

Error: package:dart_eval/src/eval/compiler/expression/method_invocation.dart 366:26 resolveInstanceMethod package:dart_eval/src/eval/compiler/expression/method_invocation.dart 259:12 _invokeWithTarget package:dart_eval/src/eval/compiler/expression/method_invocation.dart 55:12 compileMethodInvocation package:dart_eval/src/eval/compiler/expression/expression.dart 38:12 compileExpression package:dart_eval/src/eval/compiler/statement/return.dart 24:9 compileReturn package:dart_eval/src/eval/compiler/statement/statement.dart 31:12 compileStatement package:dart_eval/src/eval/compiler/statement/block.dart 17:20 compileBlock package:dart_eval/src/eval/compiler/declaration/function.dart 84:14 compileFunctionDeclaration package:dart_eval/src/eval/compiler/declaration/declaration.dart 24:5 compileDeclaration package:dart_eval/src/eval/compiler/compiler.dart 492:11 Compiler.compileSources.. dart:collection _LinkedHashMapMixin.forEach package:dart_eval/src/eval/compiler/compiler.dart 481:15 Compiler.compileSources. dart:collection _LinkedHashMapMixin.forEach package:dart_eval/src/eval/compiler/compiler.dart 477:32 Compiler.compileSources package:dart_eval/src/eval/compiler/compiler.dart 164:12 Compiler.compile test/bridge_test.dart 59:32 main..

type 'VariableDeclarationImpl' is not a subtype of type 'MethodDeclaration' in type cast