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

Cannot access null value from map #196

Open
Noobware1 opened this issue Mar 21, 2024 · 1 comment
Open

Cannot access null value from map #196

Noobware1 opened this issue Mar 21, 2024 · 1 comment

Comments

@Noobware1
Copy link
Contributor

 final runtime = Compiler().compileWriteAndLoad({
    'example': {
      'main.dart': '''
import 'dart:convert';

String main() {
    final json = jsonDecode("""{
    "title": "One Piece Movie 01",
    "type": "movie",
    "year": 2000,
    "poster": {
      "formats": ["jpeg", "webp"],
      "sm": "one-piece-movie-01-9b77-sm",
      "aspectRatio": 0.7,
      "hq": "one-piece-movie-01-9b77-hq"
    },
    "episode_duration": 3052
  }""");

  bool useEnglish = true;
  final String title;
  final String? englishTitle = json['title_en'];
  if (useEnglish && englishTitle != null && englishTitle.isNotEmpty) {
    title = englishTitle;
  } else {
    title = json['title'];
  }

  return title;

}

'''
    }
  });

  final value = runtime.executeLib('package:example/main.dart', 'main');

  print(value);

Excepted: One Piece Movie 01
Actual:

Unhandled exception:
dart_eval runtime exception: type 'Null' is not a subtype of type '$Instance' in type cast
#0      PushObjectProperty.run (package:dart_eval/src/eval/runtime/ops/objects.dart:283:31)
#1      Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:867:12)
#2      Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:854:12)
at main()

RUNTIME STATE
=============
Program offset: 108
Stack sample: [L4: Instance of '$null', L5: $"title_en", L6: null, L7: Instance of '$null', L8: false, L9: ${true}, L10: ${true}, *L11: null, L12: null, L13: null]
Args sample: []
Call stack: [0, -1]
TRACE:
102: LogicalNot (L8)
103: BoxBool (L3)
104: BoxBool (L9)
105: PushArg (L9)
106: InvokeDynamic (L3.C3)
107: PushReturnValue ()
108: PushObjectProperty (L6.C4)  <<< EXCEPTION
109: PushReturnValue ()
110: PushArg (L11)
111: InvokeDynamic (L10.C3)

#0      Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:876:7)
#1      Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:854:12)
#2      main (file:///C:/Users/freem/OneDrive/Desktop/Projects/dart_eval/test/l.dart:40:25)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
@apps-auth
Copy link

#217

Resolve this problem

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

2 participants