mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:59:47 +00:00
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:
parent
9b8f917b90
commit
041f98ca8c
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
18
tests/compiler/dart2js_extra/local_function_call2_test.dart
Normal file
18
tests/compiler/dart2js_extra/local_function_call2_test.dart
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue