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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart

Issue 2993193002: When reordering constructor initializers, use correct types for temp vars. (Closed)
Patch Set: Created 3 years, 4 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.kernel_procedure_builder; 5 library fasta.kernel_procedure_builder;
6 6
7 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'
8 show TypeInferrer;
9
7 import 'package:kernel/ast.dart' 10 import 'package:kernel/ast.dart'
8 show 11 show
9 Arguments, 12 Arguments,
10 AsyncMarker, 13 AsyncMarker,
11 Constructor, 14 Constructor,
12 ConstructorInvocation, 15 ConstructorInvocation,
13 DartType, 16 DartType,
14 DynamicType, 17 DynamicType,
15 EmptyStatement, 18 EmptyStatement,
16 Expression, 19 Expression,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 385
383 Constructor get target => constructor; 386 Constructor get target => constructor;
384 387
385 void checkSuperOrThisInitializer(Initializer initializer) { 388 void checkSuperOrThisInitializer(Initializer initializer) {
386 if (superInitializer != null || redirectingInitializer != null) { 389 if (superInitializer != null || redirectingInitializer != null) {
387 return deprecated_inputError(fileUri, initializer.fileOffset, 390 return deprecated_inputError(fileUri, initializer.fileOffset,
388 "Can't have more than one 'super' or 'this' initializer."); 391 "Can't have more than one 'super' or 'this' initializer.");
389 } 392 }
390 } 393 }
391 394
392 void addInitializer(Initializer initializer) { 395 void addInitializer(Initializer initializer, TypeInferrer typeInferrer) {
393 List<Initializer> initializers = constructor.initializers; 396 List<Initializer> initializers = constructor.initializers;
394 if (initializer is SuperInitializer) { 397 if (initializer is SuperInitializer) {
395 checkSuperOrThisInitializer(initializer); 398 checkSuperOrThisInitializer(initializer);
396 superInitializer = initializer; 399 superInitializer = initializer;
397 } else if (initializer is RedirectingInitializer) { 400 } else if (initializer is RedirectingInitializer) {
398 checkSuperOrThisInitializer(initializer); 401 checkSuperOrThisInitializer(initializer);
399 redirectingInitializer = initializer; 402 redirectingInitializer = initializer;
400 if (constructor.initializers.isNotEmpty) { 403 if (constructor.initializers.isNotEmpty) {
401 deprecated_inputError(fileUri, initializer.fileOffset, 404 deprecated_inputError(fileUri, initializer.fileOffset,
402 "'this' initializer must be the only initializer."); 405 "'this' initializer must be the only initializer.");
(...skipping 10 matching lines...) Expand all
413 initializers.removeLast(); 416 initializers.removeLast();
414 if (!hasMovedSuperInitializer) { 417 if (!hasMovedSuperInitializer) {
415 // To preserve correct evaluation order, the arguments to super call 418 // To preserve correct evaluation order, the arguments to super call
416 // must be evaluated before [initializer]. Once the super initializer 419 // must be evaluated before [initializer]. Once the super initializer
417 // has been moved once, the arguments are evaluated in the correct 420 // has been moved once, the arguments are evaluated in the correct
418 // order. 421 // order.
419 hasMovedSuperInitializer = true; 422 hasMovedSuperInitializer = true;
420 Arguments arguments = superInitializer.arguments; 423 Arguments arguments = superInitializer.arguments;
421 List<Expression> positional = arguments.positional; 424 List<Expression> positional = arguments.positional;
422 for (int i = 0; i < positional.length; i++) { 425 for (int i = 0; i < positional.length; i++) {
423 VariableDeclaration variable = 426 var type = typeInferrer.typeSchemaEnvironment.strongMode
ahe 2017/08/08 13:31:18 Missing type on variable.
Paul Berry 2017/08/08 16:42:25 IMHO this is ok--type inference will infer DartTyp
ahe 2017/08/08 17:35:44 I wouldn't have complained if hadn't used a type o
424 new VariableDeclaration.forValue(positional[i], isFinal: true); 427 ? positional[i].getStaticType(typeInferrer.typeSchemaEnvironment)
428 : const DynamicType();
429 VariableDeclaration variable = new VariableDeclaration.forValue(
430 positional[i],
431 isFinal: true,
432 type: type);
425 initializers 433 initializers
426 .add(new LocalInitializer(variable)..parent = constructor); 434 .add(new LocalInitializer(variable)..parent = constructor);
427 positional[i] = new VariableGet(variable)..parent = arguments; 435 positional[i] = new VariableGet(variable)..parent = arguments;
428 } 436 }
429 for (NamedExpression named in arguments.named) { 437 for (NamedExpression named in arguments.named) {
430 VariableDeclaration variable = 438 VariableDeclaration variable =
431 new VariableDeclaration.forValue(named.value, isFinal: true); 439 new VariableDeclaration.forValue(named.value, isFinal: true);
432 named.value = new VariableGet(variable)..parent = named; 440 named.value = new VariableGet(variable)..parent = named;
433 initializers 441 initializers
434 .add(new LocalInitializer(variable)..parent = constructor); 442 .add(new LocalInitializer(variable)..parent = constructor);
435 } 443 }
436 } 444 }
437 initializers.add(initializer..parent = constructor); 445 initializers.add(initializer..parent = constructor);
438 initializers.add(superInitializer); 446 initializers.add(superInitializer);
439 return; 447 return;
440 } 448 }
441 initializers.add(initializer); 449 initializers.add(initializer);
442 initializer.parent = constructor; 450 initializer.parent = constructor;
443 } 451 }
444 } 452 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698