Files
sdk/pkg/front_end/testcases/const_functions/const_functions_closures.dart.weak.expect
T
Kallen Tu 6f90c5531e [cfe] Closures and environment changes for const functions.
Change-Id: If844a28192c1eef4dcbb62075ae07e86297f2c92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193920
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2021-04-08 15:09:39 +00:00

87 lines
2.2 KiB
Plaintext

library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
import "package:expect/expect.dart" as exp;
import "package:expect/expect.dart";
static const field core::int var1 = #C1;
static const field core::int var2 = #C1;
static const field core::int y = #C2;
static const field core::int var3 = #C3;
static const field core::int var4 = #C1;
static const field core::int var5 = #C4;
static const field core::int var6 = #C4;
static method foo() → core::int {
() → () → core::int f = () → () → core::int {
core::int count = 0;
function baz() → core::int {
count = count.{core::num::+}(1);
return count;
}
return baz;
};
() → core::int c1 = f.call();
() → core::int c2 = f.call();
core::int c1_val1 = c1.call();
assert(c1_val1.{core::num::==}(1));
core::int c1_val2 = c1.call();
assert(c1_val2.{core::num::==}(2));
core::int c1_val3 = c1.call();
assert(c1_val3.{core::num::==}(3));
core::int c2_val1 = c2.call();
assert(c1_val1.{core::num::==}(1));
core::int c2_val2 = c2.call();
assert(c1_val2.{core::num::==}(2));
core::int c2_val3 = c2.call();
assert(c1_val3.{core::num::==}(3));
return 0;
}
static method fn() → core::int {
return (() → core::int => 0).call();
}
static method fn3() → core::int {
core::int y = 2;
return y;
}
static method fn4() → core::int {
core::int x = 0;
function innerFn() → core::int {
return x;
}
return innerFn.call();
}
static method fn5(core::int a) → core::int {
function recurse(core::int b) → core::int {
if(b.{core::num::==}(1))
return 1;
core::int result = recurse.call(b.{core::num::-}(1));
return b.{core::num::*}(result);
}
return recurse.call(a);
}
static method fn6(core::int a) → core::int {
function recurse() → core::int {
a = a.{core::num::-}(1);
if(a.{core::num::==}(1))
return 1;
return a.{core::num::*}(recurse.call());
}
return recurse.call();
}
static method main() → void {
exp::Expect::equals(#C1, 0);
exp::Expect::equals(#C1, 0);
exp::Expect::equals(#C3, 2);
exp::Expect::equals(#C1, 0);
exp::Expect::equals(#C4, 6);
exp::Expect::equals(#C4, 6);
}
constants {
#C1 = 0
#C2 = 1
#C3 = 2
#C4 = 6
}