OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 6044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6055 rightOperand.accept(this); | 6055 rightOperand.accept(this); |
6056 } finally { | 6056 } finally { |
6057 _overrideManager.exitScope(); | 6057 _overrideManager.exitScope(); |
6058 } | 6058 } |
6059 } | 6059 } |
6060 } else { | 6060 } else { |
6061 // TODO(leafp): Do downwards inference using the declared type | 6061 // TODO(leafp): Do downwards inference using the declared type |
6062 // of the binary operator for other cases. | 6062 // of the binary operator for other cases. |
6063 if (operatorType == TokenType.QUESTION_QUESTION) { | 6063 if (operatorType == TokenType.QUESTION_QUESTION) { |
6064 InferenceContext.setTypeFromNode(leftOperand, node); | 6064 InferenceContext.setTypeFromNode(leftOperand, node); |
6065 InferenceContext.setTypeFromNode(rightOperand, node); | |
6066 } | 6065 } |
6067 leftOperand?.accept(this); | 6066 leftOperand?.accept(this); |
6067 if (operatorType == TokenType.QUESTION_QUESTION) { | |
6068 // Set the right side, either from the context, or using the information | |
6069 // from the left side if it is more precise. | |
6070 DartType contextType = InferenceContext.getType(node); | |
6071 DartType leftType = leftOperand?.staticType; | |
6072 if (contextType == null || contextType.isDynamic) { | |
6073 contextType = leftType; | |
6074 } | |
6075 InferenceContext.setType(rightOperand, contextType); | |
6076 } | |
6068 rightOperand?.accept(this); | 6077 rightOperand?.accept(this); |
6069 } | 6078 } |
6070 node.accept(elementResolver); | 6079 node.accept(elementResolver); |
6071 node.accept(typeAnalyzer); | 6080 node.accept(typeAnalyzer); |
6072 return null; | 6081 return null; |
6073 } | 6082 } |
6074 | 6083 |
6075 @override | 6084 @override |
6076 Object visitBlockFunctionBody(BlockFunctionBody node) { | 6085 Object visitBlockFunctionBody(BlockFunctionBody node) { |
6077 _overrideManager.enterScope(); | 6086 _overrideManager.enterScope(); |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6940 node.initializer != null) { | 6949 node.initializer != null) { |
6941 (element as ConstVariableElement).constantInitializer = | 6950 (element as ConstVariableElement).constantInitializer = |
6942 new ConstantAstCloner().cloneNode(node.initializer); | 6951 new ConstantAstCloner().cloneNode(node.initializer); |
6943 } | 6952 } |
6944 return null; | 6953 return null; |
6945 } | 6954 } |
6946 | 6955 |
6947 @override | 6956 @override |
6948 visitVariableDeclarationList(VariableDeclarationList node) { | 6957 visitVariableDeclarationList(VariableDeclarationList node) { |
6949 for (VariableDeclaration decl in node.variables) { | 6958 for (VariableDeclaration decl in node.variables) { |
6959 // TODO(jmesserly): this sets the type even when it's implicitly dynamic. | |
6960 // Do we need to do thiat? | |
Leaf
2016/08/04 22:26:44
Might even be worth filtering out dynamic in setTy
Jennifer Messerly
2016/08/04 22:57:49
Oh! good idea. I'll move the TODO and do it in a f
| |
6950 InferenceContext.setType(decl, decl.element?.type); | 6961 InferenceContext.setType(decl, decl.element?.type); |
6951 } | 6962 } |
6952 super.visitVariableDeclarationList(node); | 6963 super.visitVariableDeclarationList(node); |
6953 } | 6964 } |
6954 | 6965 |
6955 @override | 6966 @override |
6956 Object visitWhileStatement(WhileStatement node) { | 6967 Object visitWhileStatement(WhileStatement node) { |
6957 // Note: since we don't call the base class, we have to maintain | 6968 // Note: since we don't call the base class, we have to maintain |
6958 // _implicitLabelScope ourselves. | 6969 // _implicitLabelScope ourselves. |
6959 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 6970 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
(...skipping 4034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10994 return null; | 11005 return null; |
10995 } | 11006 } |
10996 if (identical(node.staticElement, variable)) { | 11007 if (identical(node.staticElement, variable)) { |
10997 if (node.inSetterContext()) { | 11008 if (node.inSetterContext()) { |
10998 result = true; | 11009 result = true; |
10999 } | 11010 } |
11000 } | 11011 } |
11001 return null; | 11012 return null; |
11002 } | 11013 } |
11003 } | 11014 } |
OLD | NEW |