Add test for calls on calls on local variables.

Change-Id: I88e67860cc2a6e69f8364a75b175088a4c920ec7
Reviewed-on: https://dart-review.googlesource.com/19566
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Johnni Winther 2017-11-10 18:08:41 +00:00
parent 9b8f917b90
commit 041f98ca8c
3 changed files with 99 additions and 0 deletions

View file

@ -13,32 +13,54 @@ main() {
namedLocalFunctionInvokeExtraNamedArgument();
closureToString();
closureCallToString();
callCompare();
callClosure();
}
////////////////////////////////////////////////////////////////////////////////
// Invocation of a named local function.
////////////////////////////////////////////////////////////////////////////////
/*element: namedLocalFunctionInvoke:[exact=JSUInt31]*/
namedLocalFunctionInvoke() {
/*[exact=JSUInt31]*/ local() => 0;
return local();
}
////////////////////////////////////////////////////////////////////////////////
// Invocation of an unnamed local function.
////////////////////////////////////////////////////////////////////////////////
/*element: unnamedLocalFunctionInvoke:[null|subclass=Object]*/
unnamedLocalFunctionInvoke() {
var local = /*[exact=JSUInt31]*/ () => 0;
return local();
}
////////////////////////////////////////////////////////////////////////////////
// Access of a named local function.
////////////////////////////////////////////////////////////////////////////////
/*element: namedLocalFunctionGet:[subclass=Closure]*/
namedLocalFunctionGet() {
/*[exact=JSUInt31]*/ local() => 0;
return local;
}
////////////////////////////////////////////////////////////////////////////////
// Call a named local function recursively.
////////////////////////////////////////////////////////////////////////////////
/*element: recursiveLocalFunction:[subclass=Closure]*/
recursiveLocalFunction() {
/*[subclass=Closure]*/ local() => local;
return local();
}
////////////////////////////////////////////////////////////////////////////////
// Call a named local function with a missing argument.
////////////////////////////////////////////////////////////////////////////////
/*element: namedLocalFunctionInvokeMissingArgument:[null|subclass=Object]*/
namedLocalFunctionInvokeMissingArgument() {
/*[exact=JSUInt31]*/ local(/*[empty]*/ x) => 0;
@ -46,6 +68,10 @@ namedLocalFunctionInvokeMissingArgument() {
return local();
}
////////////////////////////////////////////////////////////////////////////////
// Call a named local function with an extra argument.
////////////////////////////////////////////////////////////////////////////////
/*element: namedLocalFunctionInvokeExtraArgument:[null|subclass=Object]*/
namedLocalFunctionInvokeExtraArgument() {
/*[exact=JSUInt31]*/ local() => 0;
@ -53,6 +79,10 @@ namedLocalFunctionInvokeExtraArgument() {
return local(0);
}
////////////////////////////////////////////////////////////////////////////////
// Call a named local function with an extra named argument.
////////////////////////////////////////////////////////////////////////////////
/*element: namedLocalFunctionInvokeExtraNamedArgument:[null|subclass=Object]*/
namedLocalFunctionInvokeExtraNamedArgument() {
/*[exact=JSUInt31]*/ local() => 0;
@ -60,6 +90,10 @@ namedLocalFunctionInvokeExtraNamedArgument() {
return local(a: 0);
}
////////////////////////////////////////////////////////////////////////////////
// Implicit .call on a local variable.
////////////////////////////////////////////////////////////////////////////////
/*element: closureToString:[exact=JSString]*/
closureToString() {
var local = /*[null]*/ () {};
@ -67,9 +101,55 @@ closureToString() {
return local. /*invoke: [subclass=Closure]*/ toString();
}
////////////////////////////////////////////////////////////////////////////////
// Explicit .call on a local variable.
////////////////////////////////////////////////////////////////////////////////
/*element: closureCallToString:[exact=JSString]*/
closureCallToString() {
var local = /*[null]*/ () {};
local.call();
return local. /*invoke: [subclass=Closure]*/ toString();
}
////////////////////////////////////////////////////////////////////////////////
// Operator == on the result of a parameter invocation.
////////////////////////////////////////////////////////////////////////////////
// TODO(johnniwinther): Avoid refinement of [compare] in the old inference.
/*ast.element: _callCompare:[null|subclass=Object]*/
/*kernel.element: _callCompare:[exact=callCompare_closure]*/
_callCompare(int /*[subclass=Closure]*/ compare(a, b)) {
compare(0, 1) == 0;
return compare;
}
/*element: callCompare:[null]*/
callCompare() {
_callCompare(/*[subclass=JSInt]*/
(/*[exact=JSUInt31]*/ a, /*[exact=JSUInt31]*/ b) =>
a /*invoke: [exact=JSUInt31]*/ - b);
}
////////////////////////////////////////////////////////////////////////////////
// Invocation on the result of a parameter invocation.
////////////////////////////////////////////////////////////////////////////////
/*element: Class1.:[exact=Class1]*/
class Class1 {
/*element: Class1.method1:[null]*/
method1() {}
}
// TODO(johnniwinther): Avoid refinement of [f] in the old inference.
/*ast.element: _callClosure:[exact=Class1]*/
/*kernel.element: _callClosure:[exact=callClosure_closure]*/
_callClosure(/*[subclass=Closure]*/ f({a})) {
f(a: new Class1()).method1();
return f;
}
/*element: callClosure:[null]*/
callClosure() {
_callClosure(/*[exact=Class1]*/ ({/*[exact=Class1]*/ a}) => a);
}

View file

@ -142,6 +142,7 @@ mirror_printer_test: Pass, Slow # Issue 25940, 16473
[ $compiler == dart2js && !$dart2js_with_kernel ]
expose_this1_test: RuntimeError # Issue 31254
expose_this2_test: RuntimeError # Issue 31254
local_function_call2_test: RuntimeError # Issue 31333
[ $compiler == dart2js && $dart2js_with_kernel && $host_checked ]
21666_test: RuntimeError

View file

@ -0,0 +1,18 @@
// Copyright (c) 2017, 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 issue 31333.
import 'package:expect/expect.dart';
main() {
Expect.throws(() => method() + 42, (e) => e is NoSuchMethodError);
}
method() {
var local = ({foo}) => 42;
local(foo: 1).isEven;
// Global type inference wrongfully refines `local` to have type JSInt.
return local;
}