Add static tests for external extension members on extension types

We have tests for whether external extension members are allowed
on certain classes, but not extension types.

Also rewords the error to be more accurate.

Change-Id: I61c1fa4c101971986b6c8e7cc778aca94908816a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358380
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
This commit is contained in:
Srujan Gaddam 2024-03-26 15:43:19 +00:00 committed by Commit Queue
parent 1232260158
commit d1a949a8e5
5 changed files with 90 additions and 33 deletions

View file

@ -10406,9 +10406,9 @@ const MessageCode messageJsInteropExternalExtensionMemberOnTypeInvalid =
const MessageCode(
"JsInteropExternalExtensionMemberOnTypeInvalid",
problemMessage:
r"""JS interop or Native class required for 'external' extension members.""",
r"""JS interop type or @Native type from an SDK web library required for 'external' extension members.""",
correctionMessage:
r"""Try adding a JS interop annotation to the on type class of the extension.""",
r"""Try making the on-type a JS interop type or an @Native SDK web library type.""",
);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.

View file

@ -5870,8 +5870,8 @@ JsInteropExtensionTypeUsedWithWrongJsAnnotation:
correctionMessage: "Try using the '@JS' annotation from 'dart:js_interop' annotation on this extension type instead."
JsInteropExternalExtensionMemberOnTypeInvalid:
problemMessage: "JS interop or Native class required for 'external' extension members."
correctionMessage: "Try adding a JS interop annotation to the on type class of the extension."
problemMessage: "JS interop type or @Native type from an SDK web library required for 'external' extension members."
correctionMessage: "Try making the on-type a JS interop type or an @Native SDK web library type."
JsInteropExternalExtensionMemberWithStaticDisallowed:
problemMessage: "External extension members with the keyword 'static' on JS interop and @Native types are disallowed."

View file

@ -102,43 +102,43 @@ class AnonymousClass {
extension ExtensionNonJS on NonJSClass {
external var field;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external final finalField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static var staticField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static final staticFinalField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external get getter;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external set setter(_);
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static get staticGetter;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static set staticSetter(_);
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external method();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static staticMethod();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external optionalParameterMethod([int? a, int b = 0]);
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external overriddenMethod();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
nonExternalMethod() => 1;
static nonExternalStaticMethod() => 2;
@ -151,7 +151,7 @@ class NonJSClass {
extension ExtensionGenericNonJS<T> on GenericNonJSClass<T> {
external T method();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
class GenericNonJSClass<T> {}

View file

@ -90,52 +90,52 @@ class AnonymousClass {
extension ExtensionNonJS on NonJSClass {
external var field;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external final finalField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static var staticField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static final staticFinalField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external get getter;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external set setter(_);
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static get staticGetter;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static set staticSetter(_);
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external method();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external static staticMethod();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external optionalParameterMethod([int? a, int b = 0]);
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
external overriddenMethod();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
@JS('fieldAnnotation')
external var annotatedField;
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
@JS('memberAnnotation')
external annotatedMethod();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
nonExternalMethod() => 1;
static nonExternalStaticMethod() => 2;
@ -148,7 +148,7 @@ class NonJSClass {
extension ExtensionGenericNonJS<T> on GenericNonJSClass<T> {
external T method();
// ^
// [web] JS interop or Native class required for 'external' extension members.
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
class GenericNonJSClass<T> {}

View file

@ -2,7 +2,8 @@
// 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.
// Test that interop extension types can only work on interop types.
// Test that interop extension types can only work on interop types and external
// extension members can't be added to non-interop extension types.
import 'dart:html';
import 'dart:js_interop';
@ -23,6 +24,12 @@ extension type EList._(List<JSAny?> _) {
// [web] Extension type member is marked 'external', but the representation type of its extension type is not a valid JS interop type.
}
extension on EObject {
external int field;
// ^
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
// dart:js_interop types.
extension type EJSObject(JSObject _) {}
@ -30,6 +37,10 @@ extension type EJSObject(JSObject _) {}
@JS()
extension type EJSString(JSString _) {}
extension on EJSObject {
external int field;
}
// package:js types.
@pkgJs.JS()
@ -41,6 +52,12 @@ extension type EPkgJs._(PkgJs _) {
// [web] Extension type member is marked 'external', but the representation type of its extension type is not a valid JS interop type.
}
extension on EPkgJs {
external int field;
// ^
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
@pkgJs.JS()
@anonymous
class Anonymous {}
@ -54,18 +71,32 @@ extension type EAnonymous._(Anonymous _) {
// [web] Extension type member is marked 'external', but the representation type of its extension type is not a valid JS interop type.
}
extension on EAnonymous {
external int field;
// ^
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
@pkgJs.JS()
@staticInterop
class PkgJsStaticInterop {}
extension type EPkgJsStaticInterop(PkgJsStaticInterop _) {}
extension on EPkgJsStaticInterop {
external int field;
}
@JS()
@staticInterop
class StaticInterop {}
extension type EStaticInterop(StaticInterop _) {}
extension on EStaticInterop {
external int field;
}
// @Native types.
extension type EWindow(Window _) {}
@ -84,6 +115,16 @@ extension type EUint32List(Uint32List _) {}
// ^
// [web] Extension type 'EUint32List' is marked with a '@JS' annotation, but its representation type is not a valid JS interop type: 'Uint32List'.
extension on EWindow {
external int field;
}
extension on EUint8List {
external int field;
// ^
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
// Extension types.
extension type EExtensionType(EJSObject _) {}
@ -91,6 +132,10 @@ extension type EExtensionType(EJSObject _) {}
@JS()
extension type EExtensionType2(EExtensionType _) {}
extension on EExtensionType {
external int field;
}
@JS()
extension type ENonInterop._(EObject _) {
// ^
@ -100,6 +145,12 @@ extension type ENonInterop._(EObject _) {
// [web] Extension type member is marked 'external', but the representation type of its extension type is not a valid JS interop type.
}
extension on ENonInterop {
external int field;
// ^
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}
extension type EExternalDartReference._(ExternalDartReference _) {
external EExternalDartReference();
// ^
@ -110,3 +161,9 @@ extension type EExternalDartReference._(ExternalDartReference _) {
extension type EExternalDartReference2._(ExternalDartReference _) {}
// ^
// [web] Extension type 'EExternalDartReference2' is marked with a '@JS' annotation, but its representation type is not a valid JS interop type: 'ExternalDartReference'.
extension on EExternalDartReference {
external int field;
// ^
// [web] JS interop type or @Native type from an SDK web library required for 'external' extension members.
}