Skip to content

[dart2js] Static JS interop using @staticInterop problem #48244

@Sunbreak

Description

@Sunbreak

Problem

BluetoothUUID has several static methods. I tried several JS interop and all failed

@js('BluetoothUUID') on class

@JS('BluetoothUUID')
class BlueUUID {
  external static Object getService(String name);
}
: Error: Non-static JS interop class 'BlueUUID' conflicts with natively supported class '_BluetoothUUID' in 'dart:html'.
Try replacing it with a static JS interop class using `@staticInterop` with extension methods, or use js_util to interact with the native object of type '_BluetoothUUID'.
class BlueUUID {

@js('BluetoothUUID.getService') on class method

@JS()
class BlueUUID {
  @JS('BluetoothUUID.getService')
  external static Object getService(String name);
}
Unhandled exception:
Unsupported operation: static members do not support "." in their names. See https://github.com/dart-lang/sdk/issues/27926
#0      ProgramCompiler._emitJSInteropStaticMemberName (package:dev_compiler/src/kernel/compiler.dart:2602:9)
#1      ProgramCompiler._emitStaticMemberName (package:dev_compiler/src/kernel/compiler.dart:2545:20)
#2      ProgramCompiler._emitStaticTarget (package:dev_compiler/src/kernel/compiler.dart:5575:11)
#3      ProgramCompiler.visitStaticInvocation (package:dev_compiler/src/kernel/compiler.dart:5509:14)
#4      StaticInvocation.accept (package:kernel/ast.dart:6294:44)
#5      ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#6      ProgramCompiler._visitInitializer (package:dev_compiler/src/kernel/compiler.dart:1780:11)
#7      ProgramCompiler.visitVariableDeclaration (package:dev_compiler/src/kernel/compiler.dart:4525:13)
#8      VariableDeclaration.accept (package:kernel/ast.dart:10436:43)
#9      ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3769:20)
#10     MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#11     ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#12     new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:188:27)
#13     new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#14     new List.of (dart:core-patch/array_patch.dart:51:28)
#15     ListIterable.toList (dart:_internal/iterable.dart:213:44)
#16     ProgramCompiler.visitBlock (package:dev_compiler/src/kernel/compiler.dart:3957:62)
#17     Block.accept (package:kernel/ast.dart:8890:43)
#18     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3769:20)
#19     ProgramCompiler._emitFunctionScopedBody (package:dev_compiler/src/kernel/compiler.dart:3802:18)
#20     ProgramCompiler._emitGeneratorFunctionExpression.emitGeneratorFn.<anonymous closure>.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:3449:30)
#21     ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2370:25)
#22     ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3605:18)
#23     ProgramCompiler._emitGeneratorFunctionExpression.emitGeneratorFn.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:3448:35)
#24     ProgramCompiler._superDisallowed (package:dev_compiler/src/kernel/compiler.dart:3615:24)
#25     ProgramCompiler._emitGeneratorFunctionExpression.emitGeneratorFn (package:dev_compiler/src/kernel/compiler.dart:3443:7)
#26     ProgramCompiler._emitGeneratorFunctionExpression (package:dev_compiler/src/kernel/compiler.dart:3536:15)
#27     ProgramCompiler._emitGeneratorFunctionBody (package:dev_compiler/src/kernel/compiler.dart:3594:20)
#28     ProgramCompiler._emitFunction (package:dev_compiler/src/kernel/compiler.dart:3385:11)
#29     ProgramCompiler._emitArrowFunction (package:dev_compiler/src/kernel/compiler.dart:6172:13)
#30     ProgramCompiler.visitFunctionExpression (package:dev_compiler/src/kernel/compiler.dart:6165:14)
#31     FunctionExpression.accept (package:kernel/ast.dart:8284:44)
#32     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#33     ProgramCompiler._emitNamedExpression (package:dev_compiler/src/kernel/compiler.dart:5606:52)
#34     ProgramCompiler._emitArgumentList (package:dev_compiler/src/kernel/compiler.dart:5598:39)
#35     ProgramCompiler.visitConstructorInvocation (package:dev_compiler/src/kernel/compiler.dart:5742:9)
#36     ConstructorInvocation.accept (package:kernel/ast.dart:6384:44)
#37     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#38     MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#39     ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#40     new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:188:27)
#41     new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#42     new List.of (dart:core-patch/array_patch.dart:51:28)
#43     ListIterable.toList (dart:_internal/iterable.dart:213:44)
#44     ProgramCompiler._visitExpressionList (package:dev_compiler/src/kernel/compiler.dart:3823:42)
#45     ProgramCompiler.visitListLiteral (package:dev_compiler/src/kernel/compiler.dart:6080:20)
#46     ListLiteral.accept (package:kernel/ast.dart:7951:44)
#47     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#48     ProgramCompiler._emitNamedExpression (package:dev_compiler/src/kernel/compiler.dart:5606:52)
#49     ProgramCompiler._emitArgumentList (package:dev_compiler/src/kernel/compiler.dart:5598:39)
#50     ProgramCompiler.visitConstructorInvocation (package:dev_compiler/src/kernel/compiler.dart:5742:9)
#51     ConstructorInvocation.accept (package:kernel/ast.dart:6384:44)
#52     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#53     ProgramCompiler._emitNamedExpression (package:dev_compiler/src/kernel/compiler.dart:5606:52)
#54     ProgramCompiler._emitArgumentList (package:dev_compiler/src/kernel/compiler.dart:5598:39)
#55     ProgramCompiler.visitConstructorInvocation (package:dev_compiler/src/kernel/compiler.dart:5742:9)
#56     ConstructorInvocation.accept (package:kernel/ast.dart:6384:44)
#57     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#58     ProgramCompiler._emitNamedExpression (package:dev_compiler/src/kernel/compiler.dart:5606:52)
#59     ProgramCompiler._emitArgumentList (package:dev_compiler/src/kernel/compiler.dart:5598:39)
#60     ProgramCompiler.visitConstructorInvocation (package:dev_compiler/src/kernel/compiler.dart:5742:9)
#61     ConstructorInvocation.accept (package:kernel/ast.dart:6384:44)
#62     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3863:20)
#63     ProgramCompiler.visitReturnStatement (package:dev_compiler/src/kernel/compiler.dart:4394:38)
#64     ReturnStatement.accept (package:kernel/ast.dart:9869:43)
#65     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3769:20)
#66     MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#67     ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#68     new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:188:27)
#69     new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#70     new List.of (dart:core-patch/array_patch.dart:51:28)
#71     ListIterable.toList (dart:_internal/iterable.dart:213:44)
#72     ProgramCompiler.visitBlock (package:dev_compiler/src/kernel/compiler.dart:3957:62)
#73     Block.accept (package:kernel/ast.dart:8890:43)
#74     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3769:20)
#75     ProgramCompiler._emitFunctionScopedBody (package:dev_compiler/src/kernel/compiler.dart:3802:18)
#76     ProgramCompiler._emitSyncFunctionBody.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:3571:17)
#77     ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2370:25)
#78     ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3605:18)
#79     ProgramCompiler._emitSyncFunctionBody (package:dev_compiler/src/kernel/compiler.dart:3567:17)
#80     ProgramCompiler._emitFunction (package:dev_compiler/src/kernel/compiler.dart:3384:11)
#81     ProgramCompiler._emitMethodDeclaration (package:dev_compiler/src/kernel/compiler.dart:1964:12)
#82     ProgramCompiler._emitClassMethods (package:dev_compiler/src/kernel/compiler.dart:1905:23)
#83     ProgramCompiler._emitClassDeclaration (package:dev_compiler/src/kernel/compiler.dart:700:21)
#84     ProgramCompiler._emitClass (package:dev_compiler/src/kernel/compiler.dart:622:21)
#85     List.forEach (dart:core-patch/growable_array.dart:410:8)
#86     ProgramCompiler._emitLibrary (package:dev_compiler/src/kernel/compiler.dart:571:23)
#87     List.forEach (dart:core-patch/growable_array.dart:410:8)
#88     ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:431:15)
#89     JavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:152:33)
#90     FrontendCompiler.writeJavascriptBundle (package:frontend_server/frontend_server.dart:650:47)
<asynchronous suspension>
#91     FrontendCompiler.compile (package:frontend_server/frontend_server.dart:558:9)
<asynchronous suspension>
#92     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1135:11)
<asynchronous suspension>
the Dart compiler exited unexpectedly.

Reproduce

Repo: https://github.com/woodemi/web_blue.dart
Branch: reproduce/static-js-interop

Evironment

[✓] Flutter (Channel stable, 2.8.1, on macOS 11.2.3 20D91 darwin-x64, locale en-CN)
    • Flutter version 2.8.1 at /Users/sunbreak/google/flutter-2.8.x
    • Upstream repository https://github.com/flutter/flutter
    • Framework revision 77d935af4d (6 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/sunbreak/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[!] Xcode - develop for iOS and macOS (Xcode 12.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.0.0.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/sunbreak/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7678000/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/sunbreak/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7621141/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Users/sunbreak/Library/Application
      Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/212.5080.55/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at /Users/sunbreak/Library/Application
      Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/212.4746.92/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.29.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 11.2.3 20D91 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 97.0.4692.99

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions