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

Side by Side Diff: pkg/analyzer/test/src/task/strong/front_end_inference_test.dart

Issue 2950213002: Infer the return types of local functions where appropriate. (Closed)
Patch Set: Created 3 years, 6 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:io'; 7 import 'dart:io';
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 362 }
363 363
364 @override 364 @override
365 visitDeclaredIdentifier(DeclaredIdentifier node) { 365 visitDeclaredIdentifier(DeclaredIdentifier node) {
366 super.visitDeclaredIdentifier(node); 366 super.visitDeclaredIdentifier(node);
367 if (node.type == null) { 367 if (node.type == null) {
368 _recordType(node.identifier.offset, node.element.type); 368 _recordType(node.identifier.offset, node.element.type);
369 } 369 }
370 } 370 }
371 371
372 @override
373 visitFunctionDeclaration(FunctionDeclaration node) {
374 super.visitFunctionDeclaration(node);
375 if (node.element is LocalElement &&
376 node.element.enclosingElement is! CompilationUnitElement) {
377 if (node.returnType == null) {
378 _instrumentation.record(
379 uri,
380 node.name.offset,
381 'returnType',
382 new _InstrumentationValueForType(
383 node.element.returnType, elementNamer));
384 }
385 var parameters = node.functionExpression.parameters;
386 for (var parameter in parameters.parameters) {
387 // Note: it's tempting to check `parameter.type == null`, but that
388 // doesn't work because of function-typed formal parameter syntax.
389 if (parameter.element.hasImplicitType) {
390 _recordType(parameter.identifier.offset, parameter.element.type);
391 }
392 }
393 }
394 }
395
372 visitFunctionExpression(FunctionExpression node) { 396 visitFunctionExpression(FunctionExpression node) {
373 super.visitFunctionExpression(node); 397 super.visitFunctionExpression(node);
374 if (node.parent is! FunctionDeclaration) { 398 if (node.parent is! FunctionDeclaration) {
375 DartType type = node.staticType; 399 DartType type = node.staticType;
376 if (type is FunctionType) { 400 if (type is FunctionType) {
377 _instrumentation.record(uri, node.parameters.offset, 'returnType', 401 _instrumentation.record(uri, node.parameters.offset, 'returnType',
378 new _InstrumentationValueForType(type.returnType, elementNamer)); 402 new _InstrumentationValueForType(type.returnType, elementNamer));
379 List<FormalParameter> parameters = node.parameters.parameters; 403 List<FormalParameter> parameters = node.parameters.parameters;
380 for (int i = 0; i < parameters.length; i++) { 404 for (int i = 0; i < parameters.length; i++) {
381 FormalParameter parameter = parameters[i]; 405 FormalParameter parameter = parameters[i];
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 607
584 /// Based on DDC code generator's `_recoverTypeArguments` 608 /// Based on DDC code generator's `_recoverTypeArguments`
585 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { 609 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) {
586 assert(identical(g.element, f.element)); 610 assert(identical(g.element, f.element));
587 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); 611 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty);
588 assert(g.typeFormals.length + g.typeArguments.length == 612 assert(g.typeFormals.length + g.typeArguments.length ==
589 f.typeArguments.length); 613 f.typeArguments.length);
590 return f.typeArguments.skip(g.typeArguments.length); 614 return f.typeArguments.skip(g.typeArguments.length);
591 } 615 }
592 } 616 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698