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

"import as" doesn't work for extending classes #213

Open anlumo opened 4 months ago

anlumo commented 4 months ago

Test case that fails:

    test('Extending prefixed class', () {
      final runtime = compiler.compileWriteAndLoad({
        'example': {
          'main.dart': '''
            import 'package:example/b1.dart' as b1;

            class ClassC extends b1.ClassB {
              @override
              int number() => 6;
            }

            int main() {
              final b = b1.ClassB();
              final c = ClassC();

              return b.number() + c.number();
            }
          ''',
          'b1.dart': '''
            class ClassB {
              ClassB();
              int number() => 4;
            }
          ''',
        }
      });

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

Test output:

00:01 +0 -1: Class tests Extending prefixed class [E]                                              
  Null check operator used on a null value
  package:dart_eval/src/eval/compiler/declaration/constructor.dart 394:77  compileDefaultConstructor
  package:dart_eval/src/eval/compiler/declaration/class.dart 38:5          compileClassDeclaration
  package:dart_eval/src/eval/compiler/declaration/declaration.dart 17:5    compileDeclaration
  package:dart_eval/src/eval/compiler/compiler.dart 492:11                 Compiler.compileSources.<fn>.<fn>
  dart:collection                                                          _LinkedHashMapMixin.forEach
  package:dart_eval/src/eval/compiler/compiler.dart 481:15                 Compiler.compileSources.<fn>
  dart:collection                                                          _LinkedHashMapMixin.forEach
  package:dart_eval/src/eval/compiler/compiler.dart 477:32                 Compiler.compileSources
  package:dart_eval/src/eval/compiler/compiler.dart 163:12                 Compiler.compile
  package:dart_eval/src/eval/compiler/compiler.dart 547:21                 Compiler.compileWriteAndLoad
  test/class_test.dart 352:32                                              main.<fn>.<fn>

Works fine without prefixed import.