[pkg:js] Language version @Native/@JS class conflict check

Bug: https://github.com/dart-lang/sdk/issues/44797

This check was previously introduced without a language version,
and therefore lead to a breaking change on SDK update. It's now
versioned for releases >= 2.13, allowing users to migrate easier.
It also adds a hint for the error, providing alternatives for
users whose code triggers this check.

Change-Id: I4f61066a917ddb18071508291cde00710802fc5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182920
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Srujan Gaddam 2021-02-05 00:23:42 +00:00 committed by commit-bot@chromium.org
parent c83135f381
commit bea97da4a2
5 changed files with 24 additions and 4 deletions

View file

@ -6026,6 +6026,8 @@ const Template<
Message Function(String name, String name2, String string3)>(
messageTemplate:
r"""JS interop class '#name' conflicts with natively supported class '#name2' in '#string3'.""",
tipTemplate:
r"""Try making the @JS class into an @anonymous class or use js_util on the JS object.""",
withArguments: _withArgumentsJsInteropNativeClassInAnnotation);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@ -6046,6 +6048,7 @@ Message _withArgumentsJsInteropNativeClassInAnnotation(
return new Message(codeJsInteropNativeClassInAnnotation,
message:
"""JS interop class '${name}' conflicts with natively supported class '${name2}' in '${string3}'.""",
tip: """Try making the @JS class into an @anonymous class or use js_util on the JS object.""",
arguments: {'name': name, 'name2': name2, 'string3': string3});
}

View file

@ -62,9 +62,6 @@ class JsInteropChecks extends RecursiveVisitor<void> {
];
bool _libraryIsGlobalNamespace = false;
// TODO(srujzs): This currently disables this check always. This check should
// instead only be disabled up until a given language version.
bool _disableJSNativeClassConflict = true;
JsInteropChecks(
this._coreTypes, this._diagnosticsReporter, this._nativeClasses);
@ -118,7 +115,8 @@ class JsInteropChecks extends RecursiveVisitor<void> {
cls.location.file);
}
}
if (!_disableJSNativeClassConflict &&
// Since this is a breaking check, it is language-versioned.
if (cls.enclosingLibrary.languageVersion >= Version(2, 13) &&
_classHasJSAnnotation &&
!_classHasAnonymousAnnotation &&
_libraryIsGlobalNamespace) {

View file

@ -4694,6 +4694,7 @@ JsInteropNamedParameters:
JsInteropNativeClassInAnnotation:
template: "JS interop class '#name' conflicts with natively supported class '#name2' in '#string3'."
tip: "Try making the @JS class into an @anonymous class or use js_util on the JS object."
JsInteropNonExternalConstructor:
template: "JS interop classes do not support non-external constructors."

View file

@ -36,6 +36,7 @@ futureor
h
https
interop
js_util
libraries.json
list.filled
loadlibrary

View file

@ -0,0 +1,17 @@
// Copyright (c) 2021, 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.
// @dart=2.12
// Test that static check does not occur before language version 2.13.
@JS()
library language_version_test;
import 'package:js/js.dart';
@JS()
class HTMLDocument {}
void main() {}