Files
sdk/tests/language/vm/regress_32204_test.dart
T
Robert Nystrom 2034061433 Migrate language_2/vm to NNBD.
Change-Id: I313a57ed7c7ea2ada75065f55a7367376f6bdae5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152183
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2020-06-25 20:39:23 +00:00

42 lines
1.1 KiB
Dart

// Copyright (c) 2018, 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.
// Verify that local functions capture `this` if their arguments refer to
// type parameters from the enclosing class.
import "package:expect/expect.dart";
typedef void B<T>(T v);
class MyFisk {}
class MyHest {}
class A<T> {
var value;
A(B<T> x) {
// This function does not capture `this` explicitly, however it needs
// to capture it in order to access T. Verify that we do it correctly.
// If `this` is not captured then foo turns into (B<dynamic>) -> Null
// which means that foo(x) would throw if T != dynamic.
f(B<T> v) {}
f(x);
}
foo<U>(B<T> x, B<U> y) {
// This function does not capture `this` explicitly, verify that it still
// can access `T`.
f(B<T> v, B<U> y) {}
f(x, y);
}
}
void main() {
new A<MyFisk>((MyFisk v) {});
new A<MyFisk>((MyFisk v) {}).foo<MyHest>((MyFisk v) {}, (MyHest v) {});
}