-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-refactoringIssues with analysis server refactoringsIssues with analysis server refactorings
Description
Originally raised at Dart-Code/Dart-Code#5584 by @lukehutch.
Given the code:
void main() {
var test = 1 + 2;
print(3 - test);
}
The output is 0
. However if you use "Inline Local" on test
you get:
void main() {
print(3 - 1 + 2);
}
Which incorrectly outputs 4
.
A failing test that can be added to test\services\refactoring\legacy\inline_local_test.dart
is:
@soloTest
Future<void> test_OK_parenthesis_plus_intoNegate() async {
await indexTestUnit('''
void f() {
var test = 1 + 2;
print(3 - test);
}
''');
_createRefactoring('test =');
// validate change
await assertSuccessfulRefactoring('''
void main() {
print(3 - (1 + 2));
}
''');
}
There's a method to determine whether to use parens here:
static bool _shouldUseParenthesis(Expression init, AstNode node) { |
However it's not clear to me whether the bug is in that method of the Precedence
s from the expressions that are being compared (it doesn't seem like there are different Precendence
s for addition/subtraction?).
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-refactoringIssues with analysis server refactoringsIssues with analysis server refactorings