Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1226823003: Improve propagation in binary expressions (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index e07053da689a29c39eb0d6bb72d028d2f4538a55..da0245a7b677ffbb3fbd1c7b7976dc617c7404c9 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -10111,6 +10111,17 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
_listener.assertNoErrors();
}
+ void test_visitBinaryExpression_minusID_propagated() {
+ // a - b
+ BinaryExpression node = AstFactory.binaryExpression(
+ _propagatedVariable(_typeProvider.intType, 'a'), TokenType.MINUS,
+ _propagatedVariable(_typeProvider.doubleType, 'b'));
+ node.propagatedElement = getMethod(_typeProvider.numType, "+");
+ _analyze(node);
+ expect(node.propagatedType, same(_typeProvider.doubleType));
+ _listener.assertNoErrors();
+ }
+
void test_visitBinaryExpression_notEquals() {
// 2 != 3
Expression node = AstFactory.binaryExpression(
@@ -10137,6 +10148,17 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
_listener.assertNoErrors();
}
+ void test_visitBinaryExpression_plusII_propagated() {
+ // a + b
+ BinaryExpression node = AstFactory.binaryExpression(
+ _propagatedVariable(_typeProvider.intType, 'a'), TokenType.PLUS,
+ _propagatedVariable(_typeProvider.intType, 'b'));
+ node.propagatedElement = getMethod(_typeProvider.numType, "+");
+ _analyze(node);
+ expect(node.propagatedType, same(_typeProvider.intType));
+ _listener.assertNoErrors();
+ }
+
void test_visitBinaryExpression_slash() {
// 2 / 2
BinaryExpression node = AstFactory.binaryExpression(
@@ -11104,6 +11126,25 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
StaticTypeAnalyzer.flattenFutures(_typeProvider, type);
/**
+ * Return a simple identifier that has been resolved to a variable element with the given type.
+ *
+ * @param type the type of the variable being represented
+ * @param variableName the name of the variable
+ * @return a simple identifier that has been resolved to a variable element with the given type
+ */
+ SimpleIdentifier _propagatedVariable(
+ InterfaceType type, String variableName) {
+ SimpleIdentifier identifier = AstFactory.identifier3(variableName);
+ VariableElementImpl element =
+ ElementFactory.localVariableElement(identifier);
+ element.type = type;
+ identifier.staticType = _typeProvider.dynamicType;
+ identifier.propagatedElement = element;
+ identifier.propagatedType = type;
+ return identifier;
+ }
+
+ /**
* Return an integer literal that has been resolved to the correct type.
*
* @param value the value of the literal

Powered by Google App Engine
This is Rietveld 408576698