mirror of
https://github.com/dart-lang/sdk
synced 2024-09-30 06:11:16 +00:00
[dart:js_interop] Clear up wording about isA requiring non-generic type argument
Closes https://github.com/dart-lang/sdk/issues/56564 CoreLibraryReviewExempt: Doc-only change. Change-Id: I0086a0778d53d850c8d746e0474d22382d5e451c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381942 Commit-Queue: Srujan Gaddam <srujzs@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
bb49ef258c
commit
e9a72b80c1
|
@ -13,7 +13,7 @@ import 'package:front_end/src/api_prototype/codes.dart'
|
|||
templateJsInteropExportClassNotMarkedExportable,
|
||||
templateJsInteropExportInvalidInteropTypeArgument,
|
||||
templateJsInteropExportInvalidTypeArgument,
|
||||
templateJsInteropIsAInvalidType,
|
||||
templateJsInteropIsAInvalidTypeVariable,
|
||||
templateJsInteropIsAObjectLiteralType,
|
||||
templateJsInteropIsAPrimitiveExtensionType;
|
||||
import 'package:kernel/ast.dart';
|
||||
|
@ -149,8 +149,10 @@ class SharedInteropTransformer extends Transformer {
|
|||
// Generated tear-offs call the original method, so ignore that
|
||||
// invocation.
|
||||
if (!_inIsATearoff) {
|
||||
assert(interopType is TypeParameterType);
|
||||
_diagnosticReporter.report(
|
||||
templateJsInteropIsAInvalidType.withArguments(interopType),
|
||||
templateJsInteropIsAInvalidTypeVariable
|
||||
.withArguments(interopType),
|
||||
invocation.fileOffset,
|
||||
invocation.name.text.length,
|
||||
invocation.location?.file);
|
||||
|
|
|
@ -3849,34 +3849,35 @@ Message _withArgumentsJsInteropFunctionToJSRequiresStaticType(DartType _type) {
|
|||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Template<Message Function(DartType _type)>
|
||||
templateJsInteropIsAInvalidType =
|
||||
templateJsInteropIsAInvalidTypeVariable =
|
||||
const Template<Message Function(DartType _type)>(
|
||||
"JsInteropIsAInvalidType",
|
||||
"JsInteropIsAInvalidTypeVariable",
|
||||
problemMessageTemplate:
|
||||
r"""Type argument '#type' needs to be an interop 'ExtensionType'.""",
|
||||
r"""Type argument '#type' provided to 'isA' cannot be a type variable and must be an interop extension type that can be determined at compile-time.""",
|
||||
correctionMessageTemplate:
|
||||
r"""Use a valid interop extension type as the type argument instead.""",
|
||||
withArguments: _withArgumentsJsInteropIsAInvalidType,
|
||||
r"""Use a valid interop extension type that can be determined at compile-time as the type argument instead.""",
|
||||
withArguments: _withArgumentsJsInteropIsAInvalidTypeVariable,
|
||||
);
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Code<Message Function(DartType _type)> codeJsInteropIsAInvalidType =
|
||||
const Code<Message Function(DartType _type)>
|
||||
codeJsInteropIsAInvalidTypeVariable =
|
||||
const Code<Message Function(DartType _type)>(
|
||||
"JsInteropIsAInvalidType",
|
||||
"JsInteropIsAInvalidTypeVariable",
|
||||
);
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
Message _withArgumentsJsInteropIsAInvalidType(DartType _type) {
|
||||
Message _withArgumentsJsInteropIsAInvalidTypeVariable(DartType _type) {
|
||||
TypeLabeler labeler = new TypeLabeler();
|
||||
List<Object> typeParts = labeler.labelType(_type);
|
||||
String type = typeParts.join();
|
||||
return new Message(
|
||||
codeJsInteropIsAInvalidType,
|
||||
codeJsInteropIsAInvalidTypeVariable,
|
||||
problemMessage:
|
||||
"""Type argument '${type}' needs to be an interop 'ExtensionType'.""" +
|
||||
"""Type argument '${type}' provided to 'isA' cannot be a type variable and must be an interop extension type that can be determined at compile-time.""" +
|
||||
labeler.originMessages,
|
||||
correctionMessage:
|
||||
"""Use a valid interop extension type as the type argument instead.""",
|
||||
"""Use a valid interop extension type that can be determined at compile-time as the type argument instead.""",
|
||||
arguments: {
|
||||
'type': _type,
|
||||
},
|
||||
|
|
|
@ -647,8 +647,8 @@ JsInteropFunctionToJSTypeParameters/analyzerCode: Fail # Web compiler specific
|
|||
JsInteropFunctionToJSTypeParameters/example: Fail # Web compiler specific
|
||||
JsInteropInvalidStaticClassMemberName/analyzerCode: Fail
|
||||
JsInteropInvalidStaticClassMemberName/example: Fail
|
||||
JsInteropIsAInvalidType/analyzerCode: Fail # Web compiler specific
|
||||
JsInteropIsAInvalidType/example: Fail # Web compiler specific
|
||||
JsInteropIsAInvalidTypeVariable/analyzerCode: Fail # Web compiler specific
|
||||
JsInteropIsAInvalidTypeVariable/example: Fail # Web compiler specific
|
||||
JsInteropIsAObjectLiteralType/analyzerCode: Fail # Web compiler specific
|
||||
JsInteropIsAObjectLiteralType/example: Fail # Web compiler specific
|
||||
JsInteropIsAPrimitiveExtensionType/analyzerCode: Fail # Web compiler specific
|
||||
|
|
|
@ -5701,9 +5701,9 @@ JsInteropExportNoExportableMembers:
|
|||
problemMessage: "Class '#name' has no exportable members in the class or the inheritance chain."
|
||||
correctionMessage: "Using `@JSExport`, annotate at least one instance member with a body or annotate a class that has such a member in the inheritance chain."
|
||||
|
||||
JsInteropIsAInvalidType:
|
||||
problemMessage: "Type argument '#type' needs to be an interop 'ExtensionType'."
|
||||
correctionMessage: "Use a valid interop extension type as the type argument instead."
|
||||
JsInteropIsAInvalidTypeVariable:
|
||||
problemMessage: "Type argument '#type' provided to 'isA' cannot be a type variable and must be an interop extension type that can be determined at compile-time."
|
||||
correctionMessage: "Use a valid interop extension type that can be determined at compile-time as the type argument instead."
|
||||
|
||||
JsInteropIsAObjectLiteralType:
|
||||
problemMessage: "Type argument '#type' has an object literal constructor. Because 'isA' uses the type's name or '@JS()' rename, this may result in an incorrect type check."
|
||||
|
|
|
@ -520,6 +520,11 @@ extension JSAnyUtilityExtension on JSAny? {
|
|||
/// Whether this <code>[JSAny]?</code> is an instance of the JavaScript type
|
||||
/// that is declared by [T].
|
||||
///
|
||||
/// Since the type-check this function emits is determined at compile-time,
|
||||
/// [T] needs to be an interop extension type that can also be determined at
|
||||
/// compile-time. In particular, `isA` can't be provided a generic type
|
||||
/// variable as a type argument.
|
||||
///
|
||||
/// This method uses a combination of `null`, `typeof`, and `instanceof`
|
||||
/// checks in order to do this check. Use this instead of `is` checks.
|
||||
///
|
||||
|
|
|
@ -33,10 +33,10 @@ extension type CustomJSString(JSString _) implements JSString {}
|
|||
void test<T extends JSAny?, U extends NonLiteral>(JSAny? any) {
|
||||
any.isA<T>();
|
||||
// ^
|
||||
// [web] Type argument 'T' needs to be an interop 'ExtensionType'.
|
||||
// [web] Type argument 'T' provided to 'isA' cannot be a type variable and must be an interop extension type that can be determined at compile-time.
|
||||
any.isA<U>();
|
||||
// ^
|
||||
// [web] Type argument 'U' needs to be an interop 'ExtensionType'.
|
||||
// [web] Type argument 'U' provided to 'isA' cannot be a type variable and must be an interop extension type that can be determined at compile-time.
|
||||
|
||||
final tearoff = 0.toJS.isA;
|
||||
// ^
|
||||
|
|
Loading…
Reference in a new issue