[VM runtime] Consider partial instantiation when printing closures (fixes #34034).

Add regression test.

Change-Id: Ie83e8dc68e853942b186314cc572b2cf075d455f
Reviewed-on: https://dart-review.googlesource.com/67681
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
This commit is contained in:
Régis Crelier 2018-08-01 15:43:48 +00:00 committed by commit-bot@chromium.org
parent c3b7f29d46
commit 804fc2add3
3 changed files with 23 additions and 5 deletions

View file

@ -22139,13 +22139,16 @@ const char* SendPort::ToCString() const {
}
const char* Closure::ToCString() const {
const Function& fun = Function::Handle(function());
Zone* zone = Thread::Current()->zone();
const Function& fun = Function::Handle(zone, function());
const bool is_implicit_closure = fun.IsImplicitClosureFunction();
const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString();
const Function& sig_fun =
Function::Handle(zone, GetInstantiatedSignature(zone));
const char* fun_sig =
String::Handle(zone, sig_fun.UserVisibleSignature()).ToCString();
const char* from = is_implicit_closure ? " from " : "";
const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
return OS::SCreate(Thread::Current()->zone(), "Closure: %s%s%s", fun_sig,
from, fun_desc);
return OS::SCreate(zone, "Closure: %s%s%s", fun_sig, from, fun_desc);
}
int64_t Closure::ComputeHash() const {

View file

@ -1939,7 +1939,7 @@ class RawClosure : public RawInstance {
// passed-in function type arguments get concatenated to the function type
// arguments of the parent that are found in the context_.
//
// delayed_type_arguments_ is used to support the parital instantiation
// delayed_type_arguments_ is used to support the partial instantiation
// feature. When this field is set to any value other than
// Object::empty_type_arguments(), the types in this vector will be passed as
// type arguments to the closure when invoked. In this case there may not be

View file

@ -0,0 +1,15 @@
// 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.
import "package:expect/expect.dart";
dynamic bar(int Function(int) f) => f;
T foo<T>(T a) => a;
void main() {
final closure = bar(foo);
String s = closure.toString();
print(s);
Expect.isTrue(s.contains("(int) => int") || s.contains("with <int>"));
}