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

Side by Side Diff: pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart

Issue 2886443003: Minor type inference fixes. (Closed)
Patch Set: Created 3 years, 7 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 import 'package:front_end/src/base/instrumentation.dart'; 5 import 'package:front_end/src/base/instrumentation.dart';
6 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; 6 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart';
7 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart'; 7 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart';
8 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart' ; 8 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart' ;
9 import 'package:front_end/src/fasta/type_inference/type_promotion.dart'; 9 import 'package:front_end/src/fasta/type_inference/type_promotion.dart';
10 import 'package:front_end/src/fasta/type_inference/type_schema.dart'; 10 import 'package:front_end/src/fasta/type_inference/type_schema.dart';
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 // Attempt to match `K` as a function type compatible with the closure (that 347 // Attempt to match `K` as a function type compatible with the closure (that
348 // is, one having n type parameters and a compatible set of formal 348 // is, one having n type parameters and a compatible set of formal
349 // parameters). If there is a successful match, let `<S0, ..., Sn>` be the 349 // parameters). If there is a successful match, let `<S0, ..., Sn>` be the
350 // set of matched type parameters and `(Q0, ..., Qm)` be the set of matched 350 // set of matched type parameters and `(Q0, ..., Qm)` be the set of matched
351 // formal parameter types, and let `N` be the return type. 351 // formal parameter types, and let `N` be the return type.
352 Substitution substitution; 352 Substitution substitution;
353 List<DartType> formalTypesFromContext = 353 List<DartType> formalTypesFromContext =
354 new List<DartType>.filled(formals.length, null); 354 new List<DartType>.filled(formals.length, null);
355 DartType returnContext; 355 DartType returnContext;
356 if (typeContext is FunctionType) { 356 if (strongMode && typeContext is FunctionType) {
357 for (int i = 0; i < formals.length; i++) { 357 for (int i = 0; i < formals.length; i++) {
358 if (i < function.positionalParameters.length) { 358 if (i < function.positionalParameters.length) {
359 formalTypesFromContext[i] = 359 formalTypesFromContext[i] =
360 _getPositionalParameterType(typeContext, i); 360 _getPositionalParameterType(typeContext, i);
361 } else { 361 } else {
362 formalTypesFromContext[i] = 362 formalTypesFromContext[i] =
363 _getNamedParameterType(typeContext, formals[i].name); 363 _getNamedParameterType(typeContext, formals[i].name);
364 } 364 }
365 } 365 }
366 returnContext = typeContext.returnType; 366 returnContext = typeContext.returnType;
(...skipping 18 matching lines...) Expand all
385 substitution = Substitution.empty; 385 substitution = Substitution.empty;
386 } 386 }
387 387
388 // Define `Ri` as follows: if `Pi` is not `_`, let `Ri` be `Pi`. 388 // Define `Ri` as follows: if `Pi` is not `_`, let `Ri` be `Pi`.
389 // Otherwise, if `Qi` is not `_`, let `Ri` be the greatest closure of 389 // Otherwise, if `Qi` is not `_`, let `Ri` be the greatest closure of
390 // `Qi[T/S]` with respect to `?`. Otherwise, let `Ri` be `dynamic`. 390 // `Qi[T/S]` with respect to `?`. Otherwise, let `Ri` be `dynamic`.
391 for (int i = 0; i < formals.length; i++) { 391 for (int i = 0; i < formals.length; i++) {
392 KernelVariableDeclaration formal = formals[i]; 392 KernelVariableDeclaration formal = formals[i];
393 if (KernelVariableDeclaration.isImplicitlyTyped(formal)) { 393 if (KernelVariableDeclaration.isImplicitlyTyped(formal)) {
394 if (formalTypesFromContext[i] != null) { 394 if (formalTypesFromContext[i] != null) {
395 formal.type = greatestClosure(coreTypes, 395 var inferredType = greatestClosure(coreTypes,
396 substitution.substituteType(formalTypesFromContext[i])); 396 substitution.substituteType(formalTypesFromContext[i]));
397 instrumentation?.record(Uri.parse(uri), formal.fileOffset, 'type',
398 new InstrumentationValueForType(inferredType));
399 formal.type = inferredType;
397 } 400 }
398 } 401 }
399 } 402 }
400 403
401 // Let `N’` be `N[T/S]`, adjusted accordingly if the closure is declared 404 // Let `N’` be `N[T/S]`, adjusted accordingly if the closure is declared
402 // with `async`, `async*`, or `sync*`. 405 // with `async`, `async*`, or `sync*`.
403 if (returnContext != null) { 406 if (returnContext != null) {
404 returnContext = substitution.substituteType(returnContext); 407 returnContext = substitution.substituteType(returnContext);
405 } 408 }
406 if (isGenerator) { 409 if (isGenerator) {
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 /// statement returning the given [type]. 890 /// statement returning the given [type].
888 void updateInferredReturnType(TypeInferrerImpl inferrer, DartType type) { 891 void updateInferredReturnType(TypeInferrerImpl inferrer, DartType type) {
889 if (_inferredReturnType == null) { 892 if (_inferredReturnType == null) {
890 _inferredReturnType = type; 893 _inferredReturnType = type;
891 } else { 894 } else {
892 _inferredReturnType = inferrer.typeSchemaEnvironment 895 _inferredReturnType = inferrer.typeSchemaEnvironment
893 .getLeastUpperBound(_inferredReturnType, type); 896 .getLeastUpperBound(_inferredReturnType, type);
894 } 897 }
895 } 898 }
896 } 899 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_formal_parameter_builder.dart ('k') | pkg/front_end/test/fasta/strong.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698