Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2015, 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.

/// @assertion Let `o` be an object, and let `u` be a fresh final variable bound
/// to o. The closurization of method `f` on object `o` is defined to be
/// equivalent to:
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
/// ```
/// where `f` is an instance method named `m` which has type parameter
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults
/// `d1, ..., dk`, using `null` for parameters whose default value is not
/// specified.
///
/// @description Check that closurization of an instance method named `m` which
/// has type parameter declarations `X1 extends B1, ..., Xs extends Bs`,
/// required parameters `p1, ..., pn`, and named parameters `pn+1, ..., pn+k`
/// with defaults `d1, ..., dk` is equivalent to
/// ```
/// <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
/// ```
/// Test a non-generic case.
/// @author sgrekhov@unipro.ru

import '../../../../Utils/expect.dart';

class C {
double m(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) {
return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1);
}
}

main() {
C o = new C();
var f = o.m;

var f1 = (int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) {
return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3);
};

Expect.equals(
f(1, 2, 3.0, p1: 4, p2: 5, p3: 6),
f1(1, 2, 3.0, p1: 4, p2: 5, p3: 6),
);
Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5));
Expect.equals(f(-1, 3, 9.1, p1: 4, p3: null), f1(-1, 3, 9.1, p1: 4));
Expect.equals(f(-1, 3, 9.1, p2: 4, p3: null), f1(-1, 3, 9.1, p2: 4));
Expect.equals(f(-1, 3, 9.1, p3: 4), f1(-1, 3, 9.1, p3: 4));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2015, 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.

/// @assertion Let `o` be an object, and let `u` be a fresh final variable bound
/// to o. The closurization of method `f` on object `o` is defined to be
/// equivalent to:
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
/// ```
/// where `f` is an instance method named `m` which has type parameter
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults
/// `d1, ..., dk`, using `null` for parameters whose default value is not
/// specified.
///
/// @description Check that closurization of an instance method named `m` which
/// has type parameter declarations `X1 extends B1, ..., Xs extends Bs`,
/// required parameters `p1, ..., pn`, and named parameters `pn+1, ..., pn+k`
/// with defaults `d1, ..., dk` is equivalent to
/// ```
/// <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
/// ```
/// Test a non-generic case when `m` calls another method.
/// @author sgrekhov@unipro.ru

import '../../../../Utils/expect.dart';

class C {
double n(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) {
return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1);
}

sum(a, b) => a + b;

double m(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) {
return sum(r3, p2) + n(r1, r2, r3, p1: p1, p2: p2, p3: p3);
}
}

main() {
C o = new C();
var f = o.m;

var f1 = (int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) {
return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3);
};

Expect.equals(
f(1, 2, 3.2, p1: 4, p2: 5, p3: 6),
f1(1, 2, 3.2, p1: 4, p2: 5, p3: 6),
);
Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5));
Expect.equals(f(-1, 3, 9.1, p1: 4, p3: null), f1(-1, 3, 9.1, p1: 4));
Expect.equals(f(-1, 3, 9.1, p2: 4, p3: null), f1(-1, 3, 9.1, p2: 4));
Expect.equals(f(-1, 3, 9.1, p3: 4), f1(-1, 3, 9.1, p3: 4));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2025, 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.

/// @assertion Let `o` be an object, and let `u` be a fresh final variable bound
/// to o. The closurization of method `f` on object `o` is defined to be
/// equivalent to:
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
/// ```
/// where `f` is an instance method named `m` which has type parameter
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults
/// `d1, ..., dk`, using `null` for parameters whose default value is not
/// specified.
/// ...
/// `B′ j, j ∈ 1..s`, are determined as follows: If `o` is an instance of a
/// non-generic class, `B′ j = Bj,j ∈ 1..s`.
///
/// @description Check that if `o` is an instance of a non-generic class, then
/// `B′ j = Bj,j ∈ 1..s`.
/// @author sgrekhov22@gmail.com

import '../../../../Utils/expect.dart';
import '../../../../Utils/static_type_helper.dart';

class C {
X0 m<X0 extends int, X1 extends num, X2 extends X1>(X1 r1, {required X2 p1}) {
return (r1 + p1) as X0;
}
}

main() {
C o = C();
final f = o.m;
f.expectStaticType<
Exactly<
X0 Function<X0 extends int, X1 extends num, X2 extends X1>(
X1 r1, {
required X2 p1,
})
>
>();
Expect.isTrue(
f is X0 Function<X0 extends int, X1 extends num, X2 extends X1>( // ignore: unnecessary_type_check
X1 r1, {
required X2 p1,
}),
);
Expect.equals(o.m<int, int, int>(1, p1: 2), f(1, p1: 2));
Expect.equals(o.m<int, num, int>(1, p1: 3), f(1, p1: 3));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2025, 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.

/// @assertion Let `o` be an object, and let `u` be a fresh final variable bound
/// to o. The closurization of method `f` on object `o` is defined to be
/// equivalent to:
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
/// ```
/// where `f` is an instance method named `m` which has type parameter
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults
/// `d1, ..., dk`, using `null` for parameters whose default value is not
/// specified.
/// ...
/// Let `X′1,...,X′s`′ be the formal type parameters of the class of `o`, and
/// `t′1,...,t′s′` be the actual type arguments. Then
/// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`.
///
/// @description Check that if `o` is an instance of a generic class, then
/// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`.
/// @author sgrekhov22@gmail.com

import '../../../../Utils/expect.dart';
import '../../../../Utils/static_type_helper.dart';

class C<T extends num> {
X0 m<X0 extends num, X1 extends T, X2 extends X1>(X1 r1, {required X2 p1}) {
return (r1 + p1) as X0;
}
}

main() {
C<int> o = C<int>();
final f = o.m;
f.expectStaticType<
Exactly<
X0 Function<X0 extends num, X1 extends int, X2 extends X1>(
X1 r1, {
required X2 p1,
})
>
>();
Expect.isTrue(
f is X0 Function<X0 extends num, X1 extends int, X2 extends X1>( // ignore: unnecessary_type_check
X1 r1, {
required X2 p1,
}),
);
Expect.equals(o.m<int, int, int>(1, p1: 2), f(1, p1: 2));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2015, 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.

/// @assertion Let `o` be an object, and let `u` be a fresh final variable bound
/// to o. The closurization of method `f` on object `o` is defined to be
/// equivalent to:
/// ...
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) =>
/// u.m<X1, ..., Xs>(p1, ..., pn+k);
/// ```
/// where `f` is an instance method named `m` which has type parameter
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
/// `p1, ..., pn`, and optional positional parameters `pn+1, ..., pn+k` with
/// defaults `d1, ..., dk`, using `null` for parameters whose default value is
/// not specified.
///
/// @description Check that closurization of an instance method named `m` which
/// has type parameter declarations `X1 extends B1, ..., Xs extends Bs`,
/// required parameters `p1, ..., pn`, and optional positional parameters
/// `pn+1, ..., pn+k` with defaults `d1, ..., dk` is equivalent to
/// ...
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) =>
/// u.m<X1, ..., Xs>(p1, ..., pn+k);
/// ```
/// Test a non-generic case.
/// @author sgrekhov@unipro.ru

import '../../../../Utils/expect.dart';

class C {
double m(int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) {
return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1);
}
}

main() {
C o = new C();
var f = o.m;

var f1 = (int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) {
return o.m(r1, r2, r3, p1, p2, p3);
};

Expect.equals(f(1, 2, 3.4, 4, 5, 6), f1(1, 2, 3.4, 4, 5, 6));
Expect.equals(f(2, 3, 8.5, 2, -3, null), f1(2, 3, 8.5));
Expect.equals(f(-1, 3, 9.1, 4), f1(-1, 3, 9.1, 4));
Expect.equals(f(-1, 3, 9.1, 4, 5), f1(-1, 3, 9.1, 4, 5));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2015, 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.

/// @description Check that closurization of an instance method named `m` which
/// has type parameter declarations `X1 extends B1, ..., Xs extends Bs`,
/// required parameters `p1, ..., pn`, and optional positional parameters
/// `pn+1, ..., pn+k` with defaults `d1, ..., dk` is equivalent to
/// ...
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) =>
/// u.m<X1, ..., Xs>(p1, ..., pn+k);
/// ```
/// Test a non-generic case when `m` calls another method.
/// @author sgrekhov@unipro.ru

import '../../../../Utils/expect.dart';

class C {
double n(int r1, int r2, double r3, p1, p2, p3) {
return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1);
}

int sum(a, b) => a + b;

double m(int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) {
return sum(r1, p1) * n(r1, r2, r3, p1, p2, p3);
}
}

main() {
C o = new C();
var f = o.m;

var f1 = (int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) {
return o.m(r1, r2, r3, p1, p2, p3);
};

Expect.equals(f(1, 2, 3.2, 4, 5, 6), f1(1, 2, 3.2, 4, 5, 6));
Expect.equals(f(2, 3, 8.5, 2, -3, null), f1(2, 3, 8.5));
Expect.equals(f(-1, 3, 9.1, 4), f1(-1, 3, 9.1, 4));
Expect.equals(f(-1, 3, 9.1, 4, 5), f1(-1, 3, 9.1, 4, 5));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2025, 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.

/// @assertion Let `o` be an object, and let `u` be a fresh final variable bound
/// to o. The closurization of method `f` on object `o` is defined to be
/// equivalent to:
/// ...
/// ```
/// - <X1 extends B′1, ..., Xs extends B′s>
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) =>
/// u.m<X1, ..., Xs>(p1, ..., pn+k);
/// ```
/// where `f` is an instance method named `m` which has type parameter
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
/// `p1, ..., pn`, and optional positional parameters `pn+1, ..., pn+k` with
/// defaults `d1, ..., dk`, using `null` for parameters whose default value is
/// not specified.
/// ...
/// `B′ j, j ∈ 1..s`, are determined as follows: If `o` is an instance of a
/// non-generic class, `B′ j = Bj,j ∈ 1..s`.
///
/// @description Check that if `o` is an instance of a non-generic class, then
/// `B′ j = Bj,j ∈ 1..s`.
/// @author sgrekhov22@gmail.com

import '../../../../Utils/expect.dart';
import '../../../../Utils/static_type_helper.dart';

class C {
X0 m<X0 extends int, X1 extends num, X2 extends X1>(X1 r1, [X2? p1]) {
return (r1 + p1!) as X0;
}
}

main() {
C o = C();
final f = o.m;
f.expectStaticType<
Exactly<
X0 Function<X0 extends int, X1 extends num, X2 extends X1>(
X1 r1, [
X2? p1,
])
>
>();
Expect.isTrue(
f is X0 Function<X0 extends int, X1 extends num, X2 extends X1>( // ignore: unnecessary_type_check
X1 r1, [
X2? p1,
]),
);
Expect.equals(o.m<int, int, int>(1, 2), f(1, 2));
Expect.equals(o.m<int, num, int>(1, 3), f(1, 3));
}
Loading