Skip to content

Commit

Permalink
added dynamic.toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
Noobware1 committed Jan 28, 2024
1 parent cd45e86 commit 8fb11ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/src/eval/shared/stdlib/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ import 'package:dart_eval/src/eval/utils/wap_helper.dart';
import 'num.dart';

const $dynamicCls = BridgeClassDef(
BridgeClassType(BridgeTypeRef(CoreTypes.dynamic),
isAbstract: true, $extends: null),
constructors: {},
wrap: true);
BridgeClassType(BridgeTypeRef(CoreTypes.dynamic),
isAbstract: true, $extends: null),
constructors: {},
wrap: true,
methods: {
'toString': BridgeMethodDef(
BridgeFunctionDef(
returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)),
params: [],
namedParams: []),
),
},
);

const $voidCls = BridgeClassDef(
BridgeClassType(BridgeTypeRef(CoreTypes.voidType), isAbstract: true),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/eval/shared/stdlib/core/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class $Object implements $Instance {

static $Value? _toString(
Runtime runtime, $Value? target, List<$Value?> args) {
return $String(target!.$value.toString());
return $String(target!.$reified.toString());
}

static const $Function __hashCode = $Function(_hashCode);
Expand Down
1 change: 0 additions & 1 deletion lib/stdlib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export '../src/eval/shared/stdlib/core/regexp.dart';
export '../src/eval/shared/stdlib/core/string_buffer.dart';
export '../src/eval/shared/stdlib/core/uri.dart';
export '../src/eval/shared/stdlib/core/stack_trace.dart';

22 changes: 22 additions & 0 deletions test/stdlib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ void main() {
}, prints('null\n'));
});

test('dynamic.toString', () {
final runtime = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
dynamic main() {
final a = abc();
print(a.toString());
}
dynamic abc() {
return {
'hello': null
};
}
''',
}
});
expect(() {
runtime.executeLib('package:example/main.dart', 'main');
}, prints('{hello: null}\n'));
});

test('List.where', () {
final runtime = compiler.compileWriteAndLoad({
'example': {
Expand Down

0 comments on commit 8fb11ea

Please sign in to comment.