@@ -63,10 +63,35 @@ class InferenceVisitor
63
63
64
64
InferenceVisitor (this .inferrer);
65
65
66
+ /// Computes uri and offset for [node] for internal errors in a way that is
67
+ /// safe for both top-level and full inference.
68
+ _UriOffset _computeUriOffset (TreeNode node) {
69
+ Uri uri;
70
+ int fileOffset;
71
+ if (! inferrer.isTopLevel) {
72
+ // In local inference we have access to the current file uri.
73
+ uri = inferrer.helper.uri;
74
+ fileOffset = node.fileOffset;
75
+ } else {
76
+ Location location = node.location;
77
+ if (location != null ) {
78
+ // Use the location file uri, if available.
79
+ uri = location.file;
80
+ fileOffset = node.fileOffset;
81
+ } else {
82
+ // Otherwise use the library file uri with no offset.
83
+ uri = inferrer.library.fileUri;
84
+ fileOffset = TreeNode .noOffset;
85
+ }
86
+ }
87
+ return new _UriOffset (uri, fileOffset);
88
+ }
89
+
66
90
ExpressionInferenceResult _unhandledExpression (
67
91
Expression node, DartType typeContext) {
68
- unhandled ("${node .runtimeType }" , "InferenceVisitor" , node.fileOffset,
69
- inferrer.helper.uri);
92
+ _UriOffset uriOffset = _computeUriOffset (node);
93
+ unhandled ("${node .runtimeType }" , "InferenceVisitor" , uriOffset.fileOffset,
94
+ uriOffset.uri);
70
95
}
71
96
72
97
@override
@@ -220,8 +245,9 @@ class InferenceVisitor
220
245
}
221
246
222
247
StatementInferenceResult _unhandledStatement (Statement node) {
223
- return unhandled ("${node .runtimeType }" , "InferenceVisitor" , node.fileOffset,
224
- inferrer.helper.uri);
248
+ _UriOffset uriOffset = _computeUriOffset (node);
249
+ return unhandled ("${node .runtimeType }" , "InferenceVisitor" ,
250
+ uriOffset.fileOffset, uriOffset.uri);
225
251
}
226
252
227
253
@override
@@ -991,11 +1017,12 @@ class InferenceVisitor
991
1017
} else if (syntheticAssignment is InvalidExpression || hasProblem) {
992
1018
return new InvalidForInVariable (syntheticAssignment);
993
1019
} else {
1020
+ _UriOffset uriOffset = _computeUriOffset (syntheticAssignment);
994
1021
return unhandled (
995
1022
"${syntheticAssignment .runtimeType }" ,
996
1023
"handleForInStatementWithoutVariable" ,
997
- syntheticAssignment .fileOffset,
998
- inferrer.helper .uri);
1024
+ uriOffset .fileOffset,
1025
+ uriOffset .uri);
999
1026
}
1000
1027
}
1001
1028
@@ -7262,3 +7289,10 @@ class InvalidForInVariable implements ForInVariable {
7262
7289
Expression inferAssignment (TypeInferrerImpl inferrer, DartType rhsType) =>
7263
7290
expression;
7264
7291
}
7292
+
7293
+ class _UriOffset {
7294
+ final Uri uri;
7295
+ final int fileOffset;
7296
+
7297
+ _UriOffset (this .uri, this .fileOffset);
7298
+ }
0 commit comments