OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be | 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be |
6 // refactored to fit into analyzer. | 6 // refactored to fit into analyzer. |
7 library analyzer.src.task.strong.checker; | 7 library analyzer.src.task.strong.checker; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 assert(functionType.optionalParameterTypes.isEmpty); | 626 assert(functionType.optionalParameterTypes.isEmpty); |
627 | 627 |
628 // Check the LHS type. | 628 // Check the LHS type. |
629 var rhsType = _getStaticType(expr.rightHandSide); | 629 var rhsType = _getStaticType(expr.rightHandSide); |
630 var lhsType = _getStaticType(expr.leftHandSide); | 630 var lhsType = _getStaticType(expr.leftHandSide); |
631 var returnType = rules.refineBinaryExpressionType( | 631 var returnType = rules.refineBinaryExpressionType( |
632 typeProvider, lhsType, op, rhsType, functionType.returnType); | 632 typeProvider, lhsType, op, rhsType, functionType.returnType); |
633 | 633 |
634 if (!rules.isSubtypeOf(returnType, lhsType)) { | 634 if (!rules.isSubtypeOf(returnType, lhsType)) { |
635 final numType = typeProvider.numType; | 635 final numType = typeProvider.numType; |
| 636 // TODO(jmesserly): this seems to duplicate logic in StaticTypeAnalyzer. |
636 // Try to fix up the numerical case if possible. | 637 // Try to fix up the numerical case if possible. |
637 if (rules.isSubtypeOf(lhsType, numType) && | 638 if (rules.isSubtypeOf(lhsType, numType) && |
638 rules.isSubtypeOf(lhsType, rhsType)) { | 639 rules.isSubtypeOf(lhsType, rhsType)) { |
639 // This is also slightly different from spec, but allows us to keep | 640 // This is also slightly different from spec, but allows us to keep |
640 // compound operators in the int += num and num += dynamic cases. | 641 // compound operators in the int += num and num += dynamic cases. |
641 _recordImplicitCast(expr.rightHandSide, rhsType, lhsType); | 642 _recordImplicitCast(expr.rightHandSide, rhsType, lhsType); |
642 } else { | 643 } else { |
| 644 // TODO(jmesserly): this results in a duplicate error, because |
| 645 // ErrorVerifier also reports it. |
643 _recordMessage(expr, StrongModeCode.STATIC_TYPE_ERROR, | 646 _recordMessage(expr, StrongModeCode.STATIC_TYPE_ERROR, |
644 [expr, returnType, lhsType]); | 647 [expr, returnType, lhsType]); |
645 } | 648 } |
646 } else { | 649 } else { |
647 // Check the RHS type. | 650 // Check the RHS type. |
648 // | 651 // |
649 // This is only needed if we didn't already need a cast, and avoids | 652 // This is only needed if we didn't already need a cast, and avoids |
650 // emitting two messages for the same expression. | 653 // emitting two messages for the same expression. |
651 _checkDowncast(expr.rightHandSide, paramTypes.first); | 654 _checkDowncast(expr.rightHandSide, paramTypes.first); |
652 } | 655 } |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 var visited = new Set<InterfaceType>(); | 1370 var visited = new Set<InterfaceType>(); |
1368 do { | 1371 do { |
1369 visited.add(current); | 1372 visited.add(current); |
1370 current.mixins.reversed.forEach( | 1373 current.mixins.reversed.forEach( |
1371 (m) => _checkIndividualOverridesFromClass(node, m, seen, true)); | 1374 (m) => _checkIndividualOverridesFromClass(node, m, seen, true)); |
1372 _checkIndividualOverridesFromClass(node, current.superclass, seen, true); | 1375 _checkIndividualOverridesFromClass(node, current.superclass, seen, true); |
1373 current = current.superclass; | 1376 current = current.superclass; |
1374 } while (!current.isObject && !visited.contains(current)); | 1377 } while (!current.isObject && !visited.contains(current)); |
1375 } | 1378 } |
1376 } | 1379 } |
OLD | NEW |