Files
sdk/tests/language_2/vm/regress_32204_test.dart
T
Vyacheslav Egorov ed5b6a3e8e [vm/kernel] Ensure that ScopeBuilder visits parameter types
Parameter types of local functions might refer to type arguments of
the receiver which means that receiver needs to be captured even
if it is not explicitly used inside a local function.

Fixes https://github.com/dart-lang/sdk/issues/32204

Bug: 32204
Change-Id: I448f0c8cbce12e9b58e1c3de9b2630ee22031d92
Reviewed-on: https://dart-review.googlesource.com/42441
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2018-02-20 19:09:15 +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) {});
}