Skip to content

Commit

Permalink
[dart2wasm] Disable disallowed external check.
Browse files Browse the repository at this point in the history
Bug: 50381
Change-Id: I2344a4d5c5b91acc44efb5d0c1ee10386eedd12c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268061
Commit-Queue: Joshua Litt <[email protected]>
Reviewed-by: Srujan Gaddam <[email protected]>
  • Loading branch information
joshualitt authored and Commit Queue committed Nov 4, 2022
1 parent 303d907 commit d4db1e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class JsInteropChecks extends RecursiveVisitor {
bool _classHasStaticInteropAnnotation = false;
bool _libraryHasJSAnnotation = false;
Map<Reference, Extension>? _libraryExtensionsIndex;
// TODO(joshualitt): These checks add value for our users, but unfortunately
// some backends support multiple native APIs. We should really make a neutral
// 'ExternalUsageVerifier` class, but until then we just disable this check on
// Dart2Wasm.
final bool enableDisallowedExternalCheck;

/// Libraries that use `external` to exclude from checks on external.
static final Iterable<String> _pathsWithAllowedDartExternalUsage = <String>[
Expand Down Expand Up @@ -83,7 +88,8 @@ class JsInteropChecks extends RecursiveVisitor {
bool _libraryIsGlobalNamespace = false;

JsInteropChecks(
this._coreTypes, this._diagnosticsReporter, this._nativeClasses)
this._coreTypes, this._diagnosticsReporter, this._nativeClasses,
{this.enableDisallowedExternalCheck = true})
: exportChecker =
ExportChecker(_diagnosticsReporter, _coreTypes.objectClass);

Expand Down Expand Up @@ -413,6 +419,8 @@ class JsInteropChecks extends RecursiveVisitor {
/// Assumes given [member] is not JS interop, and reports an error if
/// [member] is `external` and not an allowed `external` usage.
void _checkDisallowedExternal(Member member) {
// Some backends have multiple native APIs.
if (!enableDisallowedExternalCheck) return;
if (member.isExternal) {
if (member.isExtensionMember) {
if (!_isNativeExtensionMember(member)) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/dart2wasm/lib/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class WasmTarget extends Target {
final jsInteropChecks = JsInteropChecks(
coreTypes,
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
_nativeClasses!);
_nativeClasses!,
enableDisallowedExternalCheck: false);
// Process and validate first before doing anything with exports.
for (Library library in interopDependentLibraries) {
jsInteropChecks.visitLibrary(library);
Expand Down
23 changes: 23 additions & 0 deletions tests/web/wasm/annotations_do_not_clash_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// SharedObjects=ffi_native_test_module

import 'package:js/js.dart';
import 'dart:ffi';

@FfiNative<Void Function()>("ffi.empty")
external void empty();

@JS()
class Foo {}

extension FooExtension on Foo {
external get neverCalled;
}

// This test should compile.
void main() {
print('Hello world');
}

0 comments on commit d4db1e8

Please sign in to comment.