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

CompileError: Unknown statement type FunctionDeclarationStatementImpl at unknown (file package:default/main.dart) #183

Open HXiaoMing opened 9 months ago

HXiaoMing commented 9 months ago

test case:

import 'package:dart_eval/dart_eval.dart';
import 'package:test/test.dart';

void main() {

  group('local function test', () {

    test('local function function', () {
      final program = '''
            int main() {
              int value = 1;

              void changeValue() {
                value = 2;
              }

              changeValue();

              return value;
            }
      ''';

      final result = eval(program, function: 'main');
      print('result $result');
    });
  });
}

Error: package:dart_eval/src/eval/compiler/statement/statement.dart 45:5 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 package:dart_eval/src/eval/eval.dart 40:28 eval test/custom/local_function_test.dart 23:22 main..

CompileError: Unknown statement type FunctionDeclarationStatementImpl at unknown (file package:default/main.dart)