Skip to content

Commit c9cf5b9

Browse files
stereotype441Commit Queue
authored and
Commit Queue
committed
Add a type parameter to TypeAnalyzer to represent type schemas.
The front end and analyzer use the same representation for types and type schemas, with the unknown type schema (`_`) treated as a pseudo-type. This creates the risk of accidentally mixing types and schemas, resulting in `_` accidentally "leaking" into the type system and showing up in static analysis results or error messages. As a step toward reducing this risk, this change adds a type parameter to `TypeAnalyzer`, preventing the shared type analysis code from being able to assume that types and schemas are represented the same. This extra discipline makes it much easier to search through the code and identify how types are manipulated vs. how type schemas are manipulated, and makes it impossible for the shared type analysis to accidentally leak `_` into the type system. I believe this change will also make it easier to implement some type inference improvements we've been contemplating, such as improved type inference of `.map(...).toList()`, as well as dart-lang/language#3471, because those improvements may require introducing new kinds of type schemas. Change-Id: Ifcd7e2c4e1172ee39719ce8c8b10d7f10f6a7b6f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345353 Reviewed-by: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 9abc9fc commit c9cf5b9

File tree

12 files changed

+576
-355
lines changed

12 files changed

+576
-355
lines changed

pkg/_fe_analyzer_shared/lib/src/type_inference/type_analysis_result.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ class ObjectPatternResult<Type extends Object, Error> {
288288
}
289289

290290
/// Container for the result of running type analysis on a pattern assignment.
291-
class PatternAssignmentAnalysisResult<Type extends Object>
292-
extends SimpleTypeAnalysisResult<Type> {
291+
class PatternAssignmentAnalysisResult<Type extends Object,
292+
TypeSchema extends Object> extends SimpleTypeAnalysisResult<Type> {
293293
/// The type schema of the pattern on the left hand size of the assignment.
294-
final Type patternSchema;
294+
final TypeSchema patternSchema;
295295

296296
PatternAssignmentAnalysisResult({
297297
required this.patternSchema,
@@ -301,9 +301,10 @@ class PatternAssignmentAnalysisResult<Type extends Object>
301301

302302
/// Container for the result of running type analysis on a pattern variable
303303
/// declaration.
304-
class PatternVariableDeclarationAnalysisResult<Type extends Object> {
304+
class PatternVariableDeclarationAnalysisResult<Type extends Object,
305+
TypeSchema extends Object> {
305306
/// The type schema of the pattern on the left hand size of the declaration.
306-
final Type patternSchema;
307+
final TypeSchema patternSchema;
307308

308309
/// The type of the initializer expression.
309310
final Type initializerType;

0 commit comments

Comments
 (0)