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

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

Issue 2900873002: Fix type inference of assignments to local variables. (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
« no previous file with comments | « no previous file | pkg/front_end/test/fasta/strong.status » ('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) 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 /// This file declares a "shadow hierarchy" of concrete classes which extend 5 /// This file declares a "shadow hierarchy" of concrete classes which extend
6 /// the kernel class hierarchy, adding methods and fields needed by the 6 /// the kernel class hierarchy, adding methods and fields needed by the
7 /// BodyBuilder. 7 /// BodyBuilder.
8 /// 8 ///
9 /// Instances of these classes may be created using the factory methods in 9 /// Instances of these classes may be created using the factory methods in
10 /// `ast_factory.dart`. 10 /// `ast_factory.dart`.
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 bool isConst: false, 1262 bool isConst: false,
1263 bool isLocalFunction: false}) 1263 bool isLocalFunction: false})
1264 : _implicitlyTyped = type == null, 1264 : _implicitlyTyped = type == null,
1265 _isLocalFunction = isLocalFunction, 1265 _isLocalFunction = isLocalFunction,
1266 super(name, 1266 super(name,
1267 initializer: initializer, 1267 initializer: initializer,
1268 type: type ?? const DynamicType(), 1268 type: type ?? const DynamicType(),
1269 isFinal: isFinal, 1269 isFinal: isFinal,
1270 isConst: isConst); 1270 isConst: isConst);
1271 1271
1272 DartType get _declaredType => _implicitlyTyped ? null : type;
1273
1274 @override 1272 @override
1275 void _inferStatement(KernelTypeInferrer inferrer) { 1273 void _inferStatement(KernelTypeInferrer inferrer) {
1276 inferrer.listener.variableDeclarationEnter(this); 1274 inferrer.listener.variableDeclarationEnter(this);
1277 var declaredType = _implicitlyTyped ? null : type; 1275 var declaredType = _implicitlyTyped ? null : type;
1278 if (initializer != null) { 1276 if (initializer != null) {
1279 var inferredType = inferrer.inferDeclarationType(inferrer.inferExpression( 1277 var inferredType = inferrer.inferDeclarationType(inferrer.inferExpression(
1280 initializer, declaredType, _implicitlyTyped)); 1278 initializer, declaredType, _implicitlyTyped));
1281 if (inferrer.strongMode && _implicitlyTyped) { 1279 if (inferrer.strongMode && _implicitlyTyped) {
1282 inferrer.instrumentation?.record(Uri.parse(inferrer.uri), fileOffset, 1280 inferrer.instrumentation?.record(Uri.parse(inferrer.uri), fileOffset,
1283 'type', new InstrumentationValueForType(inferredType)); 1281 'type', new InstrumentationValueForType(inferredType));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 KernelVariableSet(VariableDeclaration variable, Expression value) 1330 KernelVariableSet(VariableDeclaration variable, Expression value)
1333 : super(variable, value); 1331 : super(variable, value);
1334 1332
1335 @override 1333 @override
1336 DartType _inferExpression( 1334 DartType _inferExpression(
1337 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 1335 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1338 var variable = this.variable as KernelVariableDeclaration; 1336 var variable = this.variable as KernelVariableDeclaration;
1339 typeNeeded = 1337 typeNeeded =
1340 inferrer.listener.variableSetEnter(this, typeContext) || typeNeeded; 1338 inferrer.listener.variableSetEnter(this, typeContext) || typeNeeded;
1341 var inferredType = 1339 var inferredType =
1342 inferrer.inferExpression(value, variable._declaredType, typeNeeded); 1340 inferrer.inferExpression(value, variable.type, typeNeeded);
1343 inferrer.listener.variableSetExit(this, inferredType); 1341 inferrer.listener.variableSetExit(this, inferredType);
1344 return inferredType; 1342 return inferredType;
1345 } 1343 }
1346 } 1344 }
1347 1345
1348 /// Concrete shadow object representing a yield statement in kernel form. 1346 /// Concrete shadow object representing a yield statement in kernel form.
1349 class KernelYieldStatement extends YieldStatement implements KernelStatement { 1347 class KernelYieldStatement extends YieldStatement implements KernelStatement {
1350 KernelYieldStatement(Expression expression, {bool isYieldStar: false}) 1348 KernelYieldStatement(Expression expression, {bool isYieldStar: false})
1351 : super(expression, isYieldStar: isYieldStar); 1349 : super(expression, isYieldStar: isYieldStar);
1352 1350
(...skipping 14 matching lines...) Expand all
1367 ? inferrer.coreTypes.streamClass 1365 ? inferrer.coreTypes.streamClass
1368 : inferrer.coreTypes.iterableClass); 1366 : inferrer.coreTypes.iterableClass);
1369 } 1367 }
1370 } 1368 }
1371 var inferredType = inferrer.inferExpression( 1369 var inferredType = inferrer.inferExpression(
1372 expression, typeContext, closureContext != null); 1370 expression, typeContext, closureContext != null);
1373 closureContext?.handleYield(inferrer, isYieldStar, inferredType); 1371 closureContext?.handleYield(inferrer, isYieldStar, inferredType);
1374 inferrer.listener.yieldStatementExit(this); 1372 inferrer.listener.yieldStatementExit(this);
1375 } 1373 }
1376 } 1374 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/test/fasta/strong.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698