ethanblake4 / dart_eval

Extensible Dart interpreter for Dart with full interop

Home Page:https://pub.dev/packages/dart_eval

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting `Null check operator used on a null value` with a rather simple code.

jumasheff opened this issue · comments

When I run the following code, I get this error Null check operator used on a null value (full stack trace is given below):

import 'package:dart_eval/dart_eval.dart';

void main() {
  const code = r'''void main() {
      const birthYear = 1990; // Туулган жылыңызды киргизиңиз
      const birthMonth = 1;   // Туулган айыңызды киргизиңиз. Мисалы, 8
      const birthDay = 23;    // Туулган күнүңүздү киргизиңиз. Мисалы, 14
      // 'final' менен бүгүнкү күндү белгилөө
      var today = DateTime.now();
      // 'final' менен туулган күндү DateTime'га айландыруу
      var birthDate = DateTime(birthYear, birthMonth, birthDay);
      // 'final' менен жашаган күндөрдүн санын эсептөө
      var daysLived = today.difference(birthDate).inDays;
      // Туулган күнүңүз жана бүгүнкү күнгө чейин жашаган күндөрүңүздү чыгаруу
      print("Сиздин туулган күнүңүз: $birthDate");
      print("Бүгүнкү күн: $today");
      print("Сиздин жашаган күндөрүңүздүн саны: $daysLived күн");
    }''';
  final compiler = Compiler();
  final runtime = compiler.compileWriteAndLoad({
    'example': {
      'main.dart': code,
    }
  });
  runtime.executeLib('package:example/main.dart', 'main');
}

Error stack trace:

Unhandled exception:
Null check operator used on a null value
#0      compileMethodInvocation (package:dart_eval/src/eval/compiler/expression/method_invocation.dart:121:34)
#1      compileExpression (package:dart_eval/src/eval/compiler/expression/expression.dart:38:12)
#2      compileVariableDeclarationList (package:dart_eval/src/eval/compiler/statement/variable_declaration.dart:33:17)
#3      compileVariableDeclarationStatement (package:dart_eval/src/eval/compiler/statement/variable_declaration.dart:15:3)
#4      compileStatement (package:dart_eval/src/eval/compiler/statement/statement.dart:23:12)
#5      compileBlock (package:dart_eval/src/eval/compiler/statement/block.dart:17:20)
#6      compileFunctionDeclaration (package:dart_eval/src/eval/compiler/declaration/function.dart:84:14)
#7      compileDeclaration (package:dart_eval/src/eval/compiler/declaration/declaration.dart:24:5)
#8      Compiler.compileSources.<anonymous closure>.<anonymous closure> (package:dart_eval/src/eval/compiler/compiler.dart:492:11)
#9      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#10     Compiler.compileSources.<anonymous closure> (package:dart_eval/src/eval/compiler/compiler.dart:481:15)
#11     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#12     Compiler.compileSources (package:dart_eval/src/eval/compiler/compiler.dart:477:32)
#13     Compiler.compile (package:dart_eval/src/eval/compiler/compiler.dart:164:12)
#14     Compiler.compileWriteAndLoad (package:dart_eval/src/eval/compiler/compiler.dart:547:21)
#15     main (package:coderunner_dart/test.dart:20:28)
#16     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Note, when I run other code examples like this, it works without errors.
Also, I tried to run the code (without dart_eval part, of course) in dartpad, it worked ok, FWIW.

Well, that's cause you can't create DateTime like this DateTime(1, 2); the default constructor for datetime is not added for some reason.

You can either wait for someone to add it or add it yourself.

DateTime default constructor will be added in next release

Waiting patiently for the next release 🙏

Forgot to close this, DateTime default constructor was added in v0.7.4