| 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 library ddc.src.checker.checker; | 5 library ddc.src.checker.checker; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 import 'package:analyzer/src/generated/scanner.dart' show Token, TokenType; | 10 import 'package:analyzer/src/generated/scanner.dart' show Token, TokenType; |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 374 |
| 375 final init = node.initializers; | 375 final init = node.initializers; |
| 376 for (int i = 0, last = init.length - 1; i < last; i++) { | 376 for (int i = 0, last = init.length - 1; i < last; i++) { |
| 377 final node = init[i]; | 377 final node = init[i]; |
| 378 if (node is SuperConstructorInvocation) { | 378 if (node is SuperConstructorInvocation) { |
| 379 _recordMessage(new InvalidSuperInvocation(node)); | 379 _recordMessage(new InvalidSuperInvocation(node)); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 @override |
| 385 visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 386 var field = node.fieldName; |
| 387 DartType staticType = _rules.elementType(field.staticElement); |
| 388 node.expression = checkAssignment(node.expression, staticType); |
| 389 node.visitChildren(this); |
| 390 } |
| 391 |
| 384 // Check invocations | 392 // Check invocations |
| 385 bool checkArgumentList(ArgumentList node, FunctionType type) { | 393 bool checkArgumentList(ArgumentList node, FunctionType type) { |
| 386 NodeList<Expression> list = node.arguments; | 394 NodeList<Expression> list = node.arguments; |
| 387 int len = list.length; | 395 int len = list.length; |
| 388 for (int i = 0; i < len; ++i) { | 396 for (int i = 0; i < len; ++i) { |
| 389 Expression arg = list[i]; | 397 Expression arg = list[i]; |
| 390 ParameterElement element = node.getStaticParameterElementFor(arg); | 398 ParameterElement element = node.getStaticParameterElementFor(arg); |
| 391 if (element == null) { | 399 if (element == null) { |
| 392 if (type.parameters.length < len) { | 400 if (type.parameters.length < len) { |
| 393 // We found an argument mismatch, the analyzer will report this too, | 401 // We found an argument mismatch, the analyzer will report this too, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if (!_rules.isSubTypeOf(defaultType, parameterType)) { | 535 if (!_rules.isSubTypeOf(defaultType, parameterType)) { |
| 528 var staticInfo = (defaultValue == null) | 536 var staticInfo = (defaultValue == null) |
| 529 ? new InvalidVariableDeclaration( | 537 ? new InvalidVariableDeclaration( |
| 530 _rules, node.identifier, parameterType) | 538 _rules, node.identifier, parameterType) |
| 531 : new StaticTypeError(_rules, defaultValue, parameterType); | 539 : new StaticTypeError(_rules, defaultValue, parameterType); |
| 532 _recordMessage(staticInfo); | 540 _recordMessage(staticInfo); |
| 533 } | 541 } |
| 534 node.visitChildren(this); | 542 node.visitChildren(this); |
| 535 } | 543 } |
| 536 | 544 |
| 545 visitFieldFormalParameter(FieldFormalParameter node) { |
| 546 var element = node.element; |
| 547 var typeName = node.type; |
| 548 if (typeName != null) { |
| 549 var type = _rules.elementType(element); |
| 550 var fieldElement = |
| 551 node.identifier.staticElement as FieldFormalParameterElement; |
| 552 var fieldType = _rules.elementType(fieldElement.field); |
| 553 if (!_rules.isSubTypeOf(type, fieldType)) { |
| 554 var staticInfo = |
| 555 new InvalidParameterDeclaration(_rules, node, fieldType); |
| 556 _recordMessage(staticInfo); |
| 557 } |
| 558 } |
| 559 node.visitChildren(this); |
| 560 } |
| 561 |
| 562 @override |
| 563 visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 564 var arguments = node.argumentList; |
| 565 var element = node.staticElement; |
| 566 if (element != null) { |
| 567 var type = _rules.elementType(node.staticElement); |
| 568 checkArgumentList(arguments, type); |
| 569 } else { |
| 570 _recordMessage(new MissingTypeError(node)); |
| 571 } |
| 572 node.visitChildren(this); |
| 573 } |
| 574 |
| 575 @override |
| 537 visitVariableDeclarationList(VariableDeclarationList node) { | 576 visitVariableDeclarationList(VariableDeclarationList node) { |
| 538 TypeName type = node.type; | 577 TypeName type = node.type; |
| 539 if (type == null) { | 578 if (type == null) { |
| 540 // No checks are needed when the type is var. Although internally the | 579 // No checks are needed when the type is var. Although internally the |
| 541 // typing rules may have inferred a more precise type for the variable | 580 // typing rules may have inferred a more precise type for the variable |
| 542 // based on the initializer. | 581 // based on the initializer. |
| 543 } else { | 582 } else { |
| 544 var dartType = getType(type); | 583 var dartType = getType(type); |
| 545 for (VariableDeclaration variable in node.variables) { | 584 for (VariableDeclaration variable in node.variables) { |
| 546 var initializer = variable.initializer; | 585 var initializer = variable.initializer; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 void _recordDynamicInvoke(AstNode node) { | 709 void _recordDynamicInvoke(AstNode node) { |
| 671 _reporter.log(new DynamicInvoke(_rules, node)); | 710 _reporter.log(new DynamicInvoke(_rules, node)); |
| 672 } | 711 } |
| 673 | 712 |
| 674 void _recordMessage(StaticInfo info) { | 713 void _recordMessage(StaticInfo info) { |
| 675 if (info == null) return; | 714 if (info == null) return; |
| 676 if (info.level >= logger.Level.SEVERE) _failure = true; | 715 if (info.level >= logger.Level.SEVERE) _failure = true; |
| 677 _reporter.log(info); | 716 _reporter.log(info); |
| 678 } | 717 } |
| 679 } | 718 } |
| OLD | NEW |