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

run test 'Using a subclassed bridge class inside the runtime' occur CompileError #172

Closed HXiaoMing closed 9 months ago

HXiaoMing commented 9 months ago

change the test 'Using a subclassed bridge class inside the runtime' source code, will occur CompileError.

before change:

@override
bool runTest(int a, {String b = 'wow'}) {
    return super.runTest(a + 2, b: b);
}

after change (I want to use super class field someNumber) :

@override
bool runTest(int a, {String b = 'wow'}) {
    return super.runTest(a + someNumber, b: b);
}

and then run the 'Using a subclassed bridge class inside the runtime' test. it will occur CompileError Could not find declaration "someNumber".

package:dart_eval/src/eval/compiler/reference.dart 323:10 IdentifierReference.getValue package:dart_eval/src/eval/compiler/expression/identifier.dart 13:48 compileIdentifier package:dart_eval/src/eval/compiler/expression/expression.dart 36:12 compileExpression package:dart_eval/src/eval/compiler/expression/binary.dart 24:11 compileBinaryExpression package:dart_eval/src/eval/compiler/expression/expression.dart 40:12 compileExpression package:dart_eval/src/eval/compiler/helpers/argument_list.dart 340:18 compileArgumentListWithBridge package:dart_eval/src/eval/compiler/expression/method_invocation.dart 269:9 _invokeWithTarget package:dart_eval/src/eval/compiler/expression/method_invocation.dart 55:12 compileMethodInvocation package:dart_eval/src/eval/compiler/expression/expression.dart 38:12 compileExpression package:dart_eval/src/eval/compiler/statement/return.dart 24:9 compileReturn package:dart_eval/src/eval/compiler/statement/statement.dart 31:12 compileStatement package:dart_eval/src/eval/compiler/statement/block.dart 17:20 compileBlock package:dart_eval/src/eval/compiler/declaration/method.dart 56:14 compileMethodDeclaration package:dart_eval/src/eval/compiler/declaration/declaration.dart 21:12 compileDeclaration package:dart_eval/src/eval/compiler/declaration/class.dart 47: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.. 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 test/bridge_test.dart 47:32 main..

CompileError: Could not find declaration "someNumber" at unknown (file package:example/main.dart)

'Using a subclassed bridge class inside the runtime' test source code:

test('Using a subclassed bridge class inside the runtime', () {
      compiler.defineBridgeClasses([$TestClass.$declaration]);

      final program = compiler.compile({
        'example': {
          'main.dart': '''
            import 'package:bridge_lib/bridge_lib.dart';

            class MyTestClass extends TestClass {
              MyTestClass(int someNumber) : super(someNumber);

              @override
              bool runTest(int a, {String b = 'wow'}) {
                return super.runTest(a + someNumber, b: b);
              }
            }

            bool main() {
              final test = MyTestClass(18);
              return test.runTest(5, b: 'cool');
            }
          '''
        }
      });

      final runtime = Runtime.ofProgram(program);

      runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart',
          'TestClass.', $TestClass.$construct,
          isBridge: true);

      expect(runtime.executeLib('package:example/main.dart', 'main'), true);
    });
Noobware1 commented 9 months ago

Just use this.someNumber

HXiaoMing commented 9 months ago

Just use this.someNumber 只需使用 this.someNumber

use this.someNumber can solve it, but use someNumber can not work? sometime use this.someNumber, it will occur warning, such as Unnecessary 'this.' qualifier. Try removing 'this.'.

Noobware1 commented 9 months ago

use this.someNumber can solve it, but use someNumber can not work? sometime use this.someNumber, it will occur warning, such as Unnecessary 'this.' qualifier. Try removing 'this.'.

You are getting the warning because dart's compiler is able to compile field references without the use of this keyword so it asks you to remove it for "cleaner code". You can turn off the warning from the analysis options file in your project.

HXiaoMing commented 9 months ago

use this.someNumber can solve it, but use someNumber can not work? sometime use this.someNumber, it will occur warning, such as Unnecessary 'this.' qualifier. Try removing 'this.'.用this.someNumber可以解决,但是用someNumber就不行了?有时使用 this.someNumber,它会出现警告,例如不必要的“this.”限定符。尝试删除“this.”。

You are getting the warning because dart's compiler is able to compile field references without the use of this keyword so it asks you to remove it for "cleaner code".您收到警告是因为 dart 的编译器能够在不使用此关键字的情况下编译字段引用,因此它要求您将其删除以获得“更干净的代码”。 You can turn off the warning from the analysis options file in your project.您可以从项目中的分析选项文件关闭警告。

It's better that both someNumber and this.someNumber work well.

ethanblake4 commented 9 months ago

Fixed in v0.7.5 (you don't have to use this anymore)