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

fix Cannot access null value from map #217

Open apps-auth opened 1 month ago

apps-auth commented 1 month ago

This pull resolve problem of acess maps keys of null or undefinded. This bellow example, with old code, return error in "lib\src\eval\runtime\ops\objects.dart" in line 100:

final method = ((object as $Instance).$getProperty(runtime, _method) as EvalFunction);

Throw error is "object" is null, not $Instance

Example code for replicate error:

Future<dynamic> main(Map<String, dynamic> args) async {
  Map<String, dynamic> object = {
    "key1": "value1",
    "key2": "value2",
  };

  int value3 = 1;

  num? _value3 = object['key3'];

  print("_value3: $_value3"); //null
  print("_value3 != null: ${_value3 != null}"); //_value3 != null: true

  if (_value3 != null) {
    value3 = _value3.toInt();
  }

  print("value3: $value3"); //1
}
apps-auth commented 1 month ago

Hello In addition to fixing the problem with accessing the null value of the Map, I continue to implement other features

ghost commented 1 month ago

Hello @apps-auth. Very rookie dev here so I imagine I am doing this incorrectly... Still wrapping my brain around all this and trying to use dart_eval for a FlutterFlow project. I noticed somewhere it seems like you made a bit of a change to class $String implements $Instance...

...I had a problem with the second pub.dev readme where it said that $String() didn't exist.

Does this change solve that problem or am I completely out to lunch and the readme should be perfectly implementable?

ethanblake4 commented 3 weeks ago

Hi, I appreciate your effort here. The Map.from and toDouble changes look great.

Unfortunately, checks like is $Value and ?? $null() are generally problematic and almost always incorrect. Typically they only use the runtime to mask the symptom of an underlying compiler issue. So, I cannot accept these changes. If you would like to make a separate PR for the Map.from and toDouble change I can accept those.