mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 18:31:32 +00:00
Migration: add support for assert initializers.
Change-Id: I581550e4359a256f846c05d4c4cec60082b4ab01 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117880 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
parent
8ffe04bcf7
commit
23def0da02
|
@ -275,6 +275,21 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
DecoratedType visitAssertInitializer(AssertInitializer node) {
|
||||
_checkExpressionNotNull(node.condition);
|
||||
if (identical(_conditionInfo?.condition, node.condition)) {
|
||||
var intentNode = _conditionInfo.trueDemonstratesNonNullIntent;
|
||||
if (intentNode != null && _conditionInfo.postDominatingIntent) {
|
||||
_graph.connect(_conditionInfo.trueDemonstratesNonNullIntent,
|
||||
_graph.never, NonNullAssertionOrigin(source, node),
|
||||
hard: true);
|
||||
}
|
||||
}
|
||||
node.message?.accept(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
DecoratedType visitAssignmentExpression(AssignmentExpression node) {
|
||||
bool isQuestionAssign = false;
|
||||
|
|
|
@ -168,8 +168,7 @@ class NamedParameterNotSuppliedOrigin extends EdgeOrigin {
|
|||
/// this class is used for the edge connecting the type of f's `i` parameter to
|
||||
/// `never`, due to the assert statement proclaiming that `i` is not `null`.
|
||||
class NonNullAssertionOrigin extends EdgeOrigin {
|
||||
NonNullAssertionOrigin(Source source, AssertStatement node)
|
||||
: super(source, node);
|
||||
NonNullAssertionOrigin(Source source, Assertion node) : super(source, node);
|
||||
}
|
||||
|
||||
/// Edge origin resulting from the presence of an explicit nullability hint
|
||||
|
|
|
@ -430,6 +430,17 @@ void f(int i) {
|
|||
assertEdge(decoratedTypeAnnotation('int i').node, never, hard: true);
|
||||
}
|
||||
|
||||
test_assert_initializer_demonstrates_non_null_intent() async {
|
||||
await analyze('''
|
||||
class C {
|
||||
C(int i)
|
||||
: assert(i != null);
|
||||
}
|
||||
''');
|
||||
|
||||
assertEdge(decoratedTypeAnnotation('int i').node, never, hard: true);
|
||||
}
|
||||
|
||||
test_assign_bound_to_type_parameter() async {
|
||||
await analyze('''
|
||||
class C<T extends List<int>> {
|
||||
|
|
Loading…
Reference in a new issue