Fix constant computing for negative shift left/right and remainder.
R=brianwilkerson@google.com
Bug: https://github.com/dart-lang/sdk/issues/33481
Change-Id: I0cc1b07b222f1fe739df6c720d7357a2453ee1b9
Reviewed-on: https://dart-review.googlesource.com/73040
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/constant/value.dart b/pkg/analyzer/lib/src/dart/constant/value.dart
index 15dc365..3e444e6 100644
--- a/pkg/analyzer/lib/src/dart/constant/value.dart
+++ b/pkg/analyzer/lib/src/dart/constant/value.dart
@@ -2243,10 +2243,10 @@
int rightValue = rightOperand.value;
if (rightValue == null) {
return UNKNOWN_VALUE;
- } else if (rightValue == 0) {
- return new DoubleState(value.toDouble() % rightValue.toDouble());
}
- return new IntState(value.remainder(rightValue));
+ if (rightValue != 0) {
+ return new IntState(value % rightValue);
+ }
} else if (rightOperand is DoubleState) {
double rightValue = rightOperand.value;
if (rightValue == null) {
@@ -2273,7 +2273,9 @@
} else if (rightValue.bitLength > 31) {
return UNKNOWN_VALUE;
}
- return new IntState(value << rightValue);
+ if (rightValue >= 0) {
+ return new IntState(value << rightValue);
+ }
} else if (rightOperand is DynamicState || rightOperand is NumState) {
return UNKNOWN_VALUE;
}
@@ -2294,7 +2296,9 @@
} else if (rightValue.bitLength > 31) {
return UNKNOWN_VALUE;
}
- return new IntState(value >> rightValue);
+ if (rightValue >= 0) {
+ return new IntState(value >> rightValue);
+ }
} else if (rightOperand is DynamicState || rightOperand is NumState) {
return UNKNOWN_VALUE;
}
diff --git a/pkg/analyzer/test/src/dart/constant/value_test.dart b/pkg/analyzer/test/src/dart/constant/value_test.dart
index 3d02cda..c0eab74 100644
--- a/pkg/analyzer/test/src/dart/constant/value_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/value_test.dart
@@ -1289,6 +1289,10 @@
_assertRemainder(_intValue(1), _intValue(7), _intValue(2));
}
+ void test_remainder_knownInt_knownInt_zero() {
+ _assertRemainder(null, _intValue(7), _intValue(0));
+ }
+
void test_remainder_knownInt_knownString() {
_assertRemainder(null, _intValue(7), _stringValue("2"));
}
@@ -1325,6 +1329,10 @@
_assertShiftLeft(_intValue(48), _intValue(6), _intValue(3));
}
+ void test_shiftLeft_knownInt_knownInt_negative() {
+ _assertShiftLeft(null, _intValue(1), _intValue(-1));
+ }
+
void test_shiftLeft_knownInt_knownString() {
_assertShiftLeft(null, _intValue(6), _stringValue(null));
}
@@ -1357,6 +1365,10 @@
_assertShiftRight(_intValue(6), _intValue(48), _intValue(3));
}
+ void test_shiftRight_knownInt_knownInt_negative() {
+ _assertShiftRight(null, _intValue(1), _intValue(-1));
+ }
+
void test_shiftRight_knownInt_knownString() {
_assertShiftRight(null, _intValue(48), _stringValue(null));
}
diff --git a/tests/language_2/language_2_analyzer.status b/tests/language_2/language_2_analyzer.status
index b89f8ee..1e5ac40 100644
--- a/tests/language_2/language_2_analyzer.status
+++ b/tests/language_2/language_2_analyzer.status
@@ -166,9 +166,6 @@
vm/debug_break_vm_test/*: Skip
vm/reflect_core_vm_test: CompileTimeError # Issue 33994
vm/regress_27201_test: SkipByDesign # Loads bad library, so will always crash.
-vm/regress_33469_test/01: Crash # http://dartbug.com/33481
-vm/regress_33469_test/02: Crash # http://dartbug.com/33481
-vm/regress_33469_test/03: MissingCompileTimeError # http://dartbug.com/33481
void/return_future_future_or_void_async_error1_test/none: CompileTimeError # issue #34319
void/return_future_or_future_or_void_sync_error2_test/none: CompileTimeError # issue #34319
void/return_future_or_void_sync_error4_test/none: CompileTimeError # issue #34319