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

Unified Diff: pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart

Issue 2947363003: Avoid a crash if an initializing formal appears in the wrong context. (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
index 61300251613832180c7f06abfbecb5ebac667d7f..8fe000017c5f4eb63722fca146d9d57d415991a1 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
@@ -514,13 +514,17 @@ abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
DartType _inferInitializingFormalType(KernelVariableDeclaration formal) {
assert(KernelVariableDeclaration.isImplicitlyTyped(formal));
- Class enclosingClass = formal.parent.parent.parent;
- for (var field in enclosingClass.fields) {
- if (field.name.name == formal.name) {
- return field.type;
+ var enclosingClass = formal.parent?.parent?.parent;
+ if (enclosingClass is Class) {
+ for (var field in enclosingClass.fields) {
+ if (field.name.name == formal.name) {
+ return field.type;
+ }
}
}
- // No matching field. The error should be reported elsewhere.
+ // No matching field, or something else has gone wrong (e.g. initializing
+ // formal outside of a class declaration). The error should be reported
+ // elsewhere, so just infer `dynamic`.
return const DynamicType();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698