From c50fcf8828e8a833ae01516f6370d6e129ed917b Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Mon, 6 Nov 2023 22:13:17 +0000 Subject: [PATCH] [ddc] Show "any" for type args of package js types Ensures that `toString()` of types that contain embedded js types will appear the same in the old and new runtime type systems. Issue: https://github.com/dart-lang/sdk/issues/48585 Change-Id: I71ec0e13943281e745bcf05e10aa36d093cbc0c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334003 Commit-Queue: Nicholas Shahan Reviewed-by: Srujan Gaddam --- CHANGELOG.md | 7 +++++++ pkg/dev_compiler/lib/src/kernel/compiler.dart | 7 +++++++ tests/dartdevc/debugger/debugger_test_golden.txt | 4 ++-- tests/dartdevc_2/debugger/debugger_test_golden.txt | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b93a7f123e..8668b06d50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,13 @@ [lints-3-0]: https://pub.dev/packages/lints/changelog#300 +#### Development JavaScript compiler (DDC) + +- Type arguments of `package:js` interop types are now printed as `any` instead + of being omitted. This is simply a change to the textual representation of + package js types that have type arguments. These type arguments are still + completely ignored by the type system at runtime. + ## 3.2.0 ### Language diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 20b6c1d49ca..83f0eb477a6 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -3519,6 +3519,13 @@ class ProgramCompiler extends ComputeOnceConstantVisitor ? getLocalClassName(c) : _emitJsNameWithoutGlobal(c); if (jsName != null) { + if (type.typeArguments.isNotEmpty) { + // This does not handle the type arguments as such, it simply includes + // them in the textual representation of this type so you can see them + // when printed. They are not used as part of the type system at all. + jsName = + '$jsName<${type.typeArguments.map((_) => 'any').join(', ')}>'; + } typeRep = runtimeCall('packageJSType(#)', [js.escapedString(jsName)]); } } diff --git a/tests/dartdevc/debugger/debugger_test_golden.txt b/tests/dartdevc/debugger/debugger_test_golden.txt index 353cd8a6c9e..4cad6ccbcab 100644 --- a/tests/dartdevc/debugger/debugger_test_golden.txt +++ b/tests/dartdevc/debugger/debugger_test_golden.txt @@ -7091,7 +7091,7 @@ Value: { "style": "background-color: #d9edf7;color: black" }, - "Instance of 'TestGenericClass'" + "Instance of 'TestGenericClass, int>'" ] ----------------------------------- Test: TestGenericClassJSInterop instance body @@ -7188,7 +7188,7 @@ Value: { "style": "background-color: #d9edf7;color: black" }, - "TestGenericClass" + "TestGenericClass, int>" ] ----------------------------------- Test: TestGenericClassJSInterop definition formatting body diff --git a/tests/dartdevc_2/debugger/debugger_test_golden.txt b/tests/dartdevc_2/debugger/debugger_test_golden.txt index 353cd8a6c9e..4cad6ccbcab 100644 --- a/tests/dartdevc_2/debugger/debugger_test_golden.txt +++ b/tests/dartdevc_2/debugger/debugger_test_golden.txt @@ -7091,7 +7091,7 @@ Value: { "style": "background-color: #d9edf7;color: black" }, - "Instance of 'TestGenericClass'" + "Instance of 'TestGenericClass, int>'" ] ----------------------------------- Test: TestGenericClassJSInterop instance body @@ -7188,7 +7188,7 @@ Value: { "style": "background-color: #d9edf7;color: black" }, - "TestGenericClass" + "TestGenericClass, int>" ] ----------------------------------- Test: TestGenericClassJSInterop definition formatting body