[tests] Add regression test for dartbug.com/60643
Change-Id: I71d506e8cb7708478466b2162ccc40f0682f308c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425941 Reviewed-by: Mark Zhou <markzipan@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
committed by
Commit Queue
parent
d791aa29fb
commit
010a4b8227
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2025, 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.
|
||||
|
||||
/// Regression test for https://github.com/dart-lang/sdk/issues/60643.
|
||||
///
|
||||
/// Getter invocations where the getter return type is a generic type argument
|
||||
/// instantiated as `dynamic` or `Function` should get runtime checks to
|
||||
/// ensure they are called correctly.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class GetterContainer<T> {
|
||||
T? _value;
|
||||
set value(T v) => _value = v;
|
||||
T get value => _value!;
|
||||
}
|
||||
|
||||
class FieldContainer<T> {
|
||||
T? value;
|
||||
}
|
||||
|
||||
void main() {
|
||||
var getterContainer = GetterContainer();
|
||||
getterContainer.value = (int i, {required String s}) {
|
||||
return 'hello world';
|
||||
};
|
||||
Expect.throws<NoSuchMethodError>(() => getterContainer.value());
|
||||
Expect.throws<NoSuchMethodError>(() => getterContainer.value(10));
|
||||
Expect.equals('hello world', getterContainer.value(10, s: 'hello'));
|
||||
|
||||
var fieldContainer = FieldContainer();
|
||||
fieldContainer.value = (int i, {required String s}) {
|
||||
return 'hello world';
|
||||
};
|
||||
Expect.throws<NoSuchMethodError>(() => fieldContainer.value());
|
||||
Expect.throws<NoSuchMethodError>(() => fieldContainer.value(10));
|
||||
Expect.equals('hello world', fieldContainer.value(10, s: 'hello'));
|
||||
|
||||
var outer = FieldContainer<dynamic>();
|
||||
var inner = GetterContainer<Function>();
|
||||
inner.value = (int i, {required String s}) {
|
||||
return 'hello world';
|
||||
};
|
||||
outer.value = inner;
|
||||
Expect.throws<NoSuchMethodError>(() => outer.value.value());
|
||||
Expect.throws<NoSuchMethodError>(() => outer.value.value(10));
|
||||
Expect.equals('hello world', outer.value.value(10, s: 'hello'));
|
||||
}
|
||||
Reference in New Issue
Block a user