Skip to content

Commit fc7049a

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: implement support for user-definable prefix expressions.
Change-Id: Ie2316625d8ed6fd9ab3aee3b592ce5b82b0cb1e8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107750 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 77aa5f0 commit fc7049a

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,7 @@ $stackTrace''');
690690

691691
@override
692692
DecoratedType visitPrefixExpression(PrefixExpression node) {
693-
/* DecoratedType operandType = */
694-
_handleAssignment(node.operand, _notNullType);
693+
var targetType = _handleAssignment(node.operand, _notNullType);
695694
var operatorType = node.operator.type;
696695
if (operatorType == TokenType.BANG) {
697696
return _nonNullableBoolType;
@@ -711,10 +710,11 @@ $stackTrace''');
711710
var calleeType = getOrComputeElementType(callee);
712711
// TODO(paulberry): substitute if necessary
713712
return calleeType.returnType;
713+
} else {
714+
var callee = node.staticElement;
715+
var calleeType = getOrComputeElementType(callee, targetType: targetType);
716+
return _handleInvocationArguments(node, [], null, calleeType, null);
714717
}
715-
// TODO(brianwilkerson) The remaining cases are invocations.
716-
_unimplemented(
717-
node, 'Prefix expression with operator ${node.operator.lexeme}');
718718
}
719719

720720
@override

pkg/nnbd_migration/test/api_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,42 @@ int f(int x, int Function(int i) g) {
17271727
await _checkSingleFileChanges(content, expected);
17281728
}
17291729

1730+
test_prefix_minus() async {
1731+
var content = '''
1732+
class C {
1733+
D operator-() => null;
1734+
}
1735+
class D {}
1736+
D test(C c) => -c;
1737+
''';
1738+
var expected = '''
1739+
class C {
1740+
D? operator-() => null;
1741+
}
1742+
class D {}
1743+
D? test(C c) => -c;
1744+
''';
1745+
await _checkSingleFileChanges(content, expected);
1746+
}
1747+
1748+
test_prefix_minus_substitute() async {
1749+
var content = '''
1750+
abstract class C<T> {
1751+
D<T> operator-();
1752+
}
1753+
class D<U> {}
1754+
D<int> test(C<int/*?*/> c) => -c;
1755+
''';
1756+
var expected = '''
1757+
abstract class C<T> {
1758+
D<T> operator-();
1759+
}
1760+
class D<U> {}
1761+
D<int?> test(C<int?/*?*/> c) => -c;
1762+
''';
1763+
await _checkSingleFileChanges(content, expected);
1764+
}
1765+
17301766
test_prefixExpression_bang() async {
17311767
var content = '''
17321768
bool f(bool b) => !b;

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,20 @@ bool f(bool b) {
19791979
assertEdge(never, return_f, hard: false);
19801980
}
19811981

1982+
test_prefixExpression_minus() async {
1983+
await analyze('''
1984+
abstract class C {
1985+
C operator-();
1986+
}
1987+
C test(C c) => -c/*check*/;
1988+
''');
1989+
assertEdge(decoratedTypeAnnotation('C operator').node,
1990+
decoratedTypeAnnotation('C test').node,
1991+
hard: false);
1992+
assertNullCheck(checkExpression('c/*check*/'),
1993+
assertEdge(decoratedTypeAnnotation('C c').node, never, hard: true));
1994+
}
1995+
19821996
test_prefixExpression_minusMinus() async {
19831997
await analyze('''
19841998
int f(int i) {

0 commit comments

Comments
 (0)