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

Side by Side Diff: lib/src/checker/checker.dart

Issue 959003003: Typecheck constructor initializers properly (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | test/checker/checker_test.dart » ('j') | test/checker/checker_test.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 366 }
367 node.visitChildren(this); 367 node.visitChildren(this);
368 } 368 }
369 369
370 /// Check constructor declaration to ensure correct super call placement. 370 /// Check constructor declaration to ensure correct super call placement.
371 @override 371 @override
372 visitConstructorDeclaration(ConstructorDeclaration node) { 372 visitConstructorDeclaration(ConstructorDeclaration node) {
373 node.visitChildren(this); 373 node.visitChildren(this);
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 (i != last && node is SuperConstructorInvocation) {
379 _recordMessage(new InvalidSuperInvocation(node)); 379 _recordMessage(new InvalidSuperInvocation(node));
380 } else if (node is ConstructorFieldInitializer) {
381 var field = node.fieldName;
382 DartType staticType = _rules.elementType(field.staticElement);
383 node.expression = checkAssignment(node.expression, staticType);
380 } 384 }
Leaf 2015/02/26 22:00:16 A little surprising that this isn't in a separate
vsm 2015/02/26 23:55:47 Done.
381 } 385 }
382 } 386 }
383 387
384 // Check invocations 388 // Check invocations
385 bool checkArgumentList(ArgumentList node, FunctionType type) { 389 bool checkArgumentList(ArgumentList node, FunctionType type) {
386 NodeList<Expression> list = node.arguments; 390 NodeList<Expression> list = node.arguments;
387 int len = list.length; 391 int len = list.length;
388 for (int i = 0; i < len; ++i) { 392 for (int i = 0; i < len; ++i) {
389 Expression arg = list[i]; 393 Expression arg = list[i];
390 ParameterElement element = node.getStaticParameterElementFor(arg); 394 ParameterElement element = node.getStaticParameterElementFor(arg);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 void _recordDynamicInvoke(AstNode node) { 674 void _recordDynamicInvoke(AstNode node) {
671 _reporter.log(new DynamicInvoke(_rules, node)); 675 _reporter.log(new DynamicInvoke(_rules, node));
672 } 676 }
673 677
674 void _recordMessage(StaticInfo info) { 678 void _recordMessage(StaticInfo info) {
675 if (info == null) return; 679 if (info == null) return;
676 if (info.level >= logger.Level.SEVERE) _failure = true; 680 if (info.level >= logger.Level.SEVERE) _failure = true;
677 _reporter.log(info); 681 _reporter.log(info);
678 } 682 }
679 } 683 }
OLDNEW
« no previous file with comments | « no previous file | test/checker/checker_test.dart » ('j') | test/checker/checker_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698