Skip to content

Commit

Permalink
Additional tests for deferred function literals.
Browse files Browse the repository at this point in the history
These tests exercise the "deferred type inference of function
literals" part of dart-lang/language#731
(improved inference for fold etc.) for super-constructor invocations
and redirecting constructor invocations, both of which have their own
code paths in the analyzer.

Change-Id: I6877ac3c07a3cca31550ba74d941d250c8410cfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241987
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
  • Loading branch information
stereotype441 authored and Commit Bot committed Apr 27, 2022
1 parent 609ba96 commit 3203a07
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,34 @@ void f({required void Function() g, Object? x}) {}
// regardless of whether the experiment is enabled.
assertType(findNode.simple('i; // (2)'), 'int?');
}

test_write_capture_deferred_redirecting_constructor() async {
await assertNoErrorsInCode('''
class C {
C(int? i) : this.other(i!, () { i = null; }, i);
C.other(Object? x, void Function() g, Object? y);
}
''');
// With the feature enabled, analysis of the closure is deferred until after
// all the other arguments to `this.other`, so the `i` passed to `y` is not
// yet write captured and retains its promoted value. With the experiment
// disabled, it is write captured immediately.
assertType(findNode.simple('i);'), _isEnabled ? 'int' : 'int?');
}

test_write_capture_deferred_super_constructor() async {
await assertNoErrorsInCode('''
class B {
B(Object? x, void Function() g, Object? y);
}
class C extends B {
C(int? i) : super(i!, () { i = null; }, i);
}
''');
// With the feature enabled, analysis of the closure is deferred until after
// all the other arguments to `this.other`, so the `i` passed to `y` is not
// yet write captured and retains its promoted value. With the experiment
// disabled, it is write captured immediately.
assertType(findNode.simple('i);'), _isEnabled ? 'int' : 'int?');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ withIdentical_rhs(int? i) {
}
}

class B {
B(Object? x, void Function() g, Object? y);
B.redirectingConstructorInvocation(int? i)
: this(i!, () {
i = null;
}, i..expectStaticType<Exactly<int?>>());
}

class C extends B {
C.superConstructorInvocation(int? i)
: super(i!, () {
i = null;
}, i..expectStaticType<Exactly<int?>>());
}

main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ withIdentical_rhs(int? i) {
}
}

class B {
B(Object? x, void Function() g, Object? y);
B.redirectingConstructorInvocation(int? i)
: this(i!, () {
i = null;
}, i..expectStaticType<Exactly<int>>());
}

class C extends B {
C.superConstructorInvocation(int? i)
: super(i!, () {
i = null;
}, i..expectStaticType<Exactly<int>>());
}

main() {}

0 comments on commit 3203a07

Please sign in to comment.