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

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

Issue 2993883002: Implement type inference for named function expressions. (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) 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 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1327
1328 @override 1328 @override
1329 DartType _inferExpression( 1329 DartType _inferExpression(
1330 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 1330 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1331 return inferrer.inferMethodInvocation( 1331 return inferrer.inferMethodInvocation(
1332 this, receiver, fileOffset, _isImplicitCall, typeContext, typeNeeded, 1332 this, receiver, fileOffset, _isImplicitCall, typeContext, typeNeeded,
1333 desugaredInvocation: this); 1333 desugaredInvocation: this);
1334 } 1334 }
1335 } 1335 }
1336 1336
1337 /// Concrete shadow object representing a named function expression.
1338 ///
1339 /// Named function expressions are not legal in Dart, but they are accepted by
1340 /// the parser and BodyBuilder for error recovery purposes.
1341 ///
1342 /// A named function expression of the form `f() { ... }` is represented as the
1343 /// kernel expression:
1344 ///
1345 /// let f = () { ... } in f
1346 class KernelNamedFunctionExpression extends Let implements KernelExpression {
1347 KernelNamedFunctionExpression(VariableDeclaration variable, Expression body)
1348 : super(variable, body);
1349
1350 @override
1351 void _collectDependencies(KernelDependencyCollector collector) {
1352 collector.collectDependencies(variable.initializer);
1353 }
1354
1355 @override
1356 DartType _inferExpression(
1357 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1358 typeNeeded =
1359 inferrer.listener.namedFunctionExpressionEnter(this, typeContext) ||
1360 typeNeeded;
1361 var inferredType =
1362 inferrer.inferExpression(variable.initializer, typeContext, true);
1363 if (inferrer.strongMode) variable.type = inferredType;
1364 if (!typeNeeded) inferredType = null;
1365 inferrer.listener.namedFunctionExpressionExit(this, inferredType);
1366 return inferredType;
1367 }
1368 }
1369
1337 /// Shadow object for [Not]. 1370 /// Shadow object for [Not].
1338 class KernelNot extends Not implements KernelExpression { 1371 class KernelNot extends Not implements KernelExpression {
1339 KernelNot(Expression operand) : super(operand); 1372 KernelNot(Expression operand) : super(operand);
1340 1373
1341 @override 1374 @override
1342 void _collectDependencies(KernelDependencyCollector collector) { 1375 void _collectDependencies(KernelDependencyCollector collector) {
1343 collector.collectDependencies(operand); 1376 collector.collectDependencies(operand);
1344 } 1377 }
1345 1378
1346 @override 1379 @override
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2462 accept(v) => unsupported("accept", -1, null); 2495 accept(v) => unsupported("accept", -1, null);
2463 2496
2464 accept1(v, arg) => unsupported("accept1", -1, null); 2497 accept1(v, arg) => unsupported("accept1", -1, null);
2465 2498
2466 getStaticType(types) => unsupported("getStaticType", -1, null); 2499 getStaticType(types) => unsupported("getStaticType", -1, null);
2467 2500
2468 transformChildren(v) => unsupported("transformChildren", -1, null); 2501 transformChildren(v) => unsupported("transformChildren", -1, null);
2469 2502
2470 visitChildren(v) => unsupported("visitChildren", -1, null); 2503 visitChildren(v) => unsupported("visitChildren", -1, null);
2471 } 2504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698