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

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

Issue 997143003: Fix for conditional expressions (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Add test case Created 5 years, 9 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') | no next file with comments »
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 /// Encapsulates how to invoke the analyzer resolver and overrides how it 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it
6 /// computes types on expressions to use our restricted set of types. 6 /// computes types on expressions to use our restricted set of types.
7 library dev_compiler.src.checker.resolver; 7 library dev_compiler.src.checker.resolver;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // variety of types, especially when we get to JS interop. 389 // variety of types, especially when we get to JS interop.
390 var args = node.argumentList.arguments; 390 var args = node.argumentList.arguments;
391 if (args.isNotEmpty && args.first is SimpleStringLiteral) { 391 if (args.isNotEmpty && args.first is SimpleStringLiteral) {
392 var coreLib = _typeProvider.objectType.element.library; 392 var coreLib = _typeProvider.objectType.element.library;
393 var classElem = coreLib.getType(args.first.stringValue); 393 var classElem = coreLib.getType(args.first.stringValue);
394 if (classElem != null) node.staticType = classElem.type; 394 if (classElem != null) node.staticType = classElem.type;
395 } 395 }
396 } 396 }
397 } 397 }
398 398
399 @override
400 visitConditionalExpression(ConditionalExpression node) {
401 // TODO(vsm): The static type of a conditional should be the LUB of the
402 // then and else expressions. The analyzer appears to compute dynamic when
403 // one or the other is the null literal. Remove this fix once the
404 // corresponding analyzer bug is fixed:
405 // https://code.google.com/p/dart/issues/detail?id=22854
406 super.visitConditionalExpression(node);
407 if (node.staticType.isDynamic) {
408 var thenExpr = node.thenExpression;
409 var elseExpr = node.elseExpression;
410 if (thenExpr.staticType.isBottom) {
411 node.staticType = elseExpr.staticType;
412 } else if (elseExpr.staticType.isBottom) {
413 node.staticType = thenExpr.staticType;
414 }
415 }
416 }
417
399 // Review note: no longer need to override visitFunctionExpression, this is 418 // Review note: no longer need to override visitFunctionExpression, this is
400 // handled by the analyzer internally. 419 // handled by the analyzer internally.
401 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? 420 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result?
402 // TODO(vsm): in visitConditionalExpression: check... LUB in rules?
403 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression 421 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression
404 // type in a (...) => expr or just the written type? 422 // type in a (...) => expr or just the written type?
405 423
406 } 424 }
407 425
408 class RestrictedTypeResolverVisitor extends TypeResolverVisitor { 426 class RestrictedTypeResolverVisitor extends TypeResolverVisitor {
409 RestrictedTypeResolverVisitor( 427 RestrictedTypeResolverVisitor(
410 Library library, Source source, TypeProvider typeProvider) 428 Library library, Source source, TypeProvider typeProvider)
411 : super.con1(library, source, typeProvider); 429 : super.con1(library, source, typeProvider);
412 430
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 element.returnType.isDynamic && 467 element.returnType.isDynamic &&
450 node.returnType == null) { 468 node.returnType == null) {
451 var type = searchTypeFor(element.enclosingElement.type, element); 469 var type = searchTypeFor(element.enclosingElement.type, element);
452 if (type != null && !type.returnType.isDynamic) { 470 if (type != null && !type.returnType.isDynamic) {
453 element.returnType = type.returnType; 471 element.returnType = type.returnType;
454 } 472 }
455 } 473 }
456 return res; 474 return res;
457 } 475 }
458 } 476 }
OLDNEW
« no previous file with comments | « no previous file | test/checker/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698