Skip to content

Commit 4028b9b

Browse files
committed
[3.0 alpha] Remove deprecated NoSuchMessageError API
Contributes to #49529 Change-Id: I2cef41b991c59869f606235929347449e17022cf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271082 Reviewed-by: Sigmund Cherem <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent d6b40b0 commit 4028b9b

File tree

8 files changed

+25
-43
lines changed

8 files changed

+25
-43
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
### Libraries
44

5+
#### `dart:core`
6+
7+
- **Breaking change** [#49529][]:
8+
- Removed the deprecated [`NoSuchMethodError`][] default constructor.
9+
Use the [`NoSuchMethodError.withInvocation`][] named constructor instead.
10+
11+
[#49529]: https://github.com/dart-lang/sdk/issues/49529
12+
[`NoSuchMethodError`]: https://api.dart.dev/stable/2.18.4/dart-core/NoSuchMethodError/NoSuchMethodError.html
13+
[`NoSuchMethodError.withInvocation`]: https://api.dart.dev/stable/2.18.4/dart-core/NoSuchMethodError/NoSuchMethodError.withInvocation.html
14+
515
#### `dart:html`
616

717
- **Breaking change**: As previously announced, the deprecated `registerElement`

sdk/lib/_internal/js_dev_runtime/patch/js_patch.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ class JsObject {
139139
if (args != null) args = List.from(args.map(_convertToJS));
140140
var fn = JS('', '#[#]', _jsObject, method);
141141
if (JS<bool>('!', 'typeof(#) !== "function"', fn)) {
142-
throw NoSuchMethodError(_jsObject, Symbol('$method'), args, {});
142+
final invocation = Invocation.method(Symbol('$method'), args, {});
143+
throw NoSuchMethodError.withInvocation(_jsObject, invocation);
143144
}
144145
return _convertToDart(JS('', '#.apply(#, #)', fn, _jsObject, args));
145146
}

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ throwNullValueError() {
9090
// TODO(vsm): Per spec, we should throw an NSM here. Technically, we ought
9191
// to thread through method info, but that uglifies the code and can't
9292
// actually be queried ... it only affects how the error is printed.
93-
throw NoSuchMethodError(null, Symbol('<Unexpected Null Value>'), null, null);
93+
throw NoSuchMethodError.withInvocation(
94+
null,
95+
Invocation.method(Symbol('<Unexpected Null Value>'), null, null),
96+
);
9497
}
9598

9699
castError(obj, expectedType) {

sdk/lib/_internal/js_runtime/lib/interceptors.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ abstract class Interceptor {
334334
// calls to use interceptor calling convention). If we did allow it, the
335335
// interceptor context would select the correct `this`.
336336
dynamic noSuchMethod(Invocation invocation) {
337-
throw new NoSuchMethodError(this, invocation.memberName,
338-
invocation.positionalArguments, invocation.namedArguments);
337+
throw new NoSuchMethodError.withInvocation(this, invocation);
339338
}
340339

341340
Type get runtimeType => getRuntimeType(this);

sdk/lib/_internal/vm/lib/errors_patch.dart

-12
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,6 @@ class NoSuchMethodError {
208208
typeArgumentsLength, typeArguments, arguments, argumentNames);
209209
}
210210

211-
// Deprecated constructor.
212-
@patch
213-
NoSuchMethodError(this._receiver, Symbol memberName,
214-
List? positionalArguments, Map<Symbol, dynamic>? namedArguments,
215-
[List? existingArgumentNames = null]) // existingArgumentNames ignored.
216-
: this._invocation = new _InvocationMirror._withType(
217-
memberName,
218-
_InvocationMirror._UNINITIALIZED,
219-
null, // Type arguments not supported in deprecated constructor.
220-
positionalArguments,
221-
namedArguments);
222-
223211
// Helper to build a map of named arguments.
224212
static Map<Symbol, dynamic> _NamedArgumentsMap(
225213
List arguments, List argumentNames) {

sdk/lib/core/errors.dart

-25
Original file line numberDiff line numberDiff line change
@@ -551,31 +551,6 @@ class NoSuchMethodError extends Error {
551551
external factory NoSuchMethodError.withInvocation(
552552
Object? receiver, Invocation invocation);
553553

554-
/// Create a [NoSuchMethodError] corresponding to a failed method call.
555-
///
556-
/// The [receiver] is the receiver of the method call.
557-
/// That is, the object on which the method was attempted called.
558-
/// If the receiver is `null`, it is interpreted as a call to a top-level
559-
/// function of a library.
560-
///
561-
/// The [memberName] is a [Symbol] representing the name of the called method
562-
/// or accessor.
563-
///
564-
/// The [positionalArguments] is a list of the positional arguments that the
565-
/// method was called with. If `null`, it is considered equivalent to the
566-
/// empty list.
567-
///
568-
/// The [namedArguments] is a map from [Symbol]s to the values of named
569-
/// arguments that the method was called with. If `null`, it is considered
570-
/// equivalent to the empty map.
571-
///
572-
/// This constructor does not handle type arguments.
573-
/// To include type variables, create an [Invocation] and use
574-
/// [NoSuchMethodError.withInvocation].
575-
@Deprecated("Use NoSuchMethod.withInvocation instead")
576-
external NoSuchMethodError(Object? receiver, Symbol memberName,
577-
List? positionalArguments, Map<Symbol, dynamic>? namedArguments);
578-
579554
external String toString();
580555
}
581556

tests/lib/mirrors/proxy_type_test.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ class CarolCaretaker implements Carol {
5656
CarolCaretaker(this._carol, this._gate);
5757

5858
foo() {
59-
if (!_gate()) throw new NoSuchMethodError(this, #foo, [], {});
59+
if (!_gate()) throw new NoSuchMethodError.withInvocation(
60+
this,
61+
Invocation.method(#foo, [], {}),
62+
);
6063
return _carol.foo();
6164
}
6265

tests/lib_2/mirrors/proxy_type_test.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class CarolCaretaker implements Carol {
5858
CarolCaretaker(this._carol, this._gate);
5959

6060
foo() {
61-
if (!_gate()) throw new NoSuchMethodError(this, #foo, [], {});
61+
if (!_gate()) throw new NoSuchMethodError.withInvocation(
62+
this,
63+
Invocation.method(#foo, [], {}),
64+
);
6265
return _carol.foo();
6366
}
6467

0 commit comments

Comments
 (0)