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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2624283003: Revert "Add support for generic function type syntax, part 1" (TBR) (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 if (_isDynamicCall(node, ft)) { 211 if (_isDynamicCall(node, ft)) {
212 // If f is Function and this is a method invocation, we should have 212 // If f is Function and this is a method invocation, we should have
213 // gotten an analyzer error, so no need to issue another error. 213 // gotten an analyzer error, so no need to issue another error.
214 _recordDynamicInvoke(node, node.function); 214 _recordDynamicInvoke(node, node.function);
215 } else { 215 } else {
216 checkArgumentList(node.argumentList, ft); 216 checkArgumentList(node.argumentList, ft);
217 } 217 }
218 } 218 }
219 219
220 DartType getType(TypeAnnotation type) { 220 DartType getType(TypeName name) {
221 return type?.type ?? DynamicTypeImpl.instance; 221 return (name == null) ? DynamicTypeImpl.instance : name.type;
222 } 222 }
223 223
224 void reset() { 224 void reset() {
225 _failure = false; 225 _failure = false;
226 } 226 }
227 227
228 @override 228 @override
229 void visitAsExpression(AsExpression node) { 229 void visitAsExpression(AsExpression node) {
230 // We could do the same check as the IsExpression below, but that is 230 // We could do the same check as the IsExpression below, but that is
231 // potentially too conservative. Instead, at runtime, we must fail hard 231 // potentially too conservative. Instead, at runtime, we must fail hard
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 @override 485 @override
486 void visitIsExpression(IsExpression node) { 486 void visitIsExpression(IsExpression node) {
487 _checkRuntimeTypeCheck(node, node.type); 487 _checkRuntimeTypeCheck(node, node.type);
488 node.visitChildren(this); 488 node.visitChildren(this);
489 } 489 }
490 490
491 @override 491 @override
492 void visitListLiteral(ListLiteral node) { 492 void visitListLiteral(ListLiteral node) {
493 DartType type = DynamicTypeImpl.instance; 493 DartType type = DynamicTypeImpl.instance;
494 if (node.typeArguments != null) { 494 if (node.typeArguments != null) {
495 NodeList<TypeAnnotation> targs = node.typeArguments.arguments; 495 NodeList<TypeName> targs = node.typeArguments.arguments;
496 if (targs.length > 0) { 496 if (targs.length > 0) {
497 type = targs[0].type; 497 type = targs[0].type;
498 } 498 }
499 } else { 499 } else {
500 DartType staticType = node.staticType; 500 DartType staticType = node.staticType;
501 if (staticType is InterfaceType) { 501 if (staticType is InterfaceType) {
502 List<DartType> targs = staticType.typeArguments; 502 List<DartType> targs = staticType.typeArguments;
503 if (targs != null && targs.length > 0) { 503 if (targs != null && targs.length > 0) {
504 type = targs[0]; 504 type = targs[0];
505 } 505 }
506 } 506 }
507 } 507 }
508 NodeList<Expression> elements = node.elements; 508 NodeList<Expression> elements = node.elements;
509 for (int i = 0; i < elements.length; i++) { 509 for (int i = 0; i < elements.length; i++) {
510 checkArgument(elements[i], type); 510 checkArgument(elements[i], type);
511 } 511 }
512 super.visitListLiteral(node); 512 super.visitListLiteral(node);
513 } 513 }
514 514
515 @override 515 @override
516 void visitMapLiteral(MapLiteral node) { 516 void visitMapLiteral(MapLiteral node) {
517 DartType ktype = DynamicTypeImpl.instance; 517 DartType ktype = DynamicTypeImpl.instance;
518 DartType vtype = DynamicTypeImpl.instance; 518 DartType vtype = DynamicTypeImpl.instance;
519 if (node.typeArguments != null) { 519 if (node.typeArguments != null) {
520 NodeList<TypeAnnotation> targs = node.typeArguments.arguments; 520 NodeList<TypeName> targs = node.typeArguments.arguments;
521 if (targs.length > 0) { 521 if (targs.length > 0) {
522 ktype = targs[0].type; 522 ktype = targs[0].type;
523 } 523 }
524 if (targs.length > 1) { 524 if (targs.length > 1) {
525 vtype = targs[1].type; 525 vtype = targs[1].type;
526 } 526 }
527 } else { 527 } else {
528 DartType staticType = node.staticType; 528 DartType staticType = node.staticType;
529 if (staticType is InterfaceType) { 529 if (staticType is InterfaceType) {
530 List<DartType> targs = staticType.typeArguments; 530 List<DartType> targs = staticType.typeArguments;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 _recordMessage( 650 _recordMessage(
651 node, 651 node,
652 StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED, 652 StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED,
653 [node.name, variableElement?.type]); 653 [node.name, variableElement?.type]);
654 } 654 }
655 return super.visitVariableDeclaration(node); 655 return super.visitVariableDeclaration(node);
656 } 656 }
657 657
658 @override 658 @override
659 void visitVariableDeclarationList(VariableDeclarationList node) { 659 void visitVariableDeclarationList(VariableDeclarationList node) {
660 TypeAnnotation type = node.type; 660 TypeName type = node.type;
661 if (type == null) { 661 if (type == null) {
662 // No checks are needed when the type is var. Although internally the 662 // No checks are needed when the type is var. Although internally the
663 // typing rules may have inferred a more precise type for the variable 663 // typing rules may have inferred a more precise type for the variable
664 // based on the initializer. 664 // based on the initializer.
665 } else { 665 } else {
666 for (VariableDeclaration variable in node.variables) { 666 for (VariableDeclaration variable in node.variables) {
667 var initializer = variable.initializer; 667 var initializer = variable.initializer;
668 if (initializer != null) { 668 if (initializer != null) {
669 checkAssignment(initializer, type.type); 669 checkAssignment(initializer, type.type);
670 } 670 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 if (type == null) { 869 if (type == null) {
870 // We have a type mismatch: the async/async*/sync* modifier does 870 // We have a type mismatch: the async/async*/sync* modifier does
871 // not match the return or yield type. We should have already gotten an 871 // not match the return or yield type. We should have already gotten an
872 // analyzer error in this case. 872 // analyzer error in this case.
873 return; 873 return;
874 } 874 }
875 // TODO(vsm): Enforce void or dynamic (to void?) when expression is null. 875 // TODO(vsm): Enforce void or dynamic (to void?) when expression is null.
876 if (expression != null) checkAssignment(expression, type); 876 if (expression != null) checkAssignment(expression, type);
877 } 877 }
878 878
879 void _checkRuntimeTypeCheck(AstNode node, TypeAnnotation annotation) { 879 void _checkRuntimeTypeCheck(AstNode node, TypeName typeName) {
880 var type = getType(annotation); 880 var type = getType(typeName);
881 if (!rules.isGroundType(type)) { 881 if (!rules.isGroundType(type)) {
882 _recordMessage(node, StrongModeCode.NON_GROUND_TYPE_CHECK_INFO, [type]); 882 _recordMessage(node, StrongModeCode.NON_GROUND_TYPE_CHECK_INFO, [type]);
883 } 883 }
884 } 884 }
885 885
886 void _checkUnary(Expression operand, Token op, MethodElement element) { 886 void _checkUnary(Expression operand, Token op, MethodElement element) {
887 bool isIncrementAssign = 887 bool isIncrementAssign =
888 op.type == TokenType.PLUS_PLUS || op.type == TokenType.MINUS_MINUS; 888 op.type == TokenType.PLUS_PLUS || op.type == TokenType.MINUS_MINUS;
889 if (op.isUserDefinableOperator || isIncrementAssign) { 889 if (op.isUserDefinableOperator || isIncrementAssign) {
890 if (element == null) { 890 if (element == null) {
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 var visited = new Set<InterfaceType>(); 1500 var visited = new Set<InterfaceType>();
1501 do { 1501 do {
1502 visited.add(current); 1502 visited.add(current);
1503 current.mixins.reversed.forEach( 1503 current.mixins.reversed.forEach(
1504 (m) => _checkIndividualOverridesFromClass(node, m, seen, true)); 1504 (m) => _checkIndividualOverridesFromClass(node, m, seen, true));
1505 _checkIndividualOverridesFromClass(node, current.superclass, seen, true); 1505 _checkIndividualOverridesFromClass(node, current.superclass, seen, true);
1506 current = current.superclass; 1506 current = current.superclass;
1507 } while (!current.isObject && !visited.contains(current)); 1507 } while (!current.isObject && !visited.contains(current));
1508 } 1508 }
1509 } 1509 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698