@@ -23,9 +23,52 @@ class RecordLiteralResolver {
23
23
24
24
ErrorReporter get errorReporter => _resolver.errorReporter;
25
25
26
+ void resolve (
27
+ RecordLiteralImpl node, {
28
+ required DartType ? contextType,
29
+ }) {
30
+ _resolveFields (node, contextType);
31
+ _buildType (node, contextType);
32
+
33
+ _reportDuplicateFieldDefinitions (node);
34
+ _reportInvalidFieldNames (node);
35
+ }
36
+
37
+ void _buildType (RecordLiteralImpl node, DartType ? contextType) {
38
+ final positionalFields = < RecordTypePositionalFieldImpl > [];
39
+ final namedFields = < RecordTypeNamedFieldImpl > [];
40
+ for (final field in node.fields) {
41
+ final fieldType = field.typeOrThrow;
42
+ if (field is NamedExpressionImpl ) {
43
+ namedFields.add (
44
+ RecordTypeNamedFieldImpl (
45
+ name: field.name.label.name,
46
+ type: fieldType,
47
+ ),
48
+ );
49
+ } else {
50
+ positionalFields.add (
51
+ RecordTypePositionalFieldImpl (
52
+ type: fieldType,
53
+ ),
54
+ );
55
+ }
56
+ }
57
+
58
+ _resolver.inferenceHelper.recordStaticType (
59
+ node,
60
+ RecordTypeImpl (
61
+ positionalFields: positionalFields,
62
+ namedFields: namedFields,
63
+ nullabilitySuffix: NullabilitySuffix .none,
64
+ ),
65
+ contextType: contextType,
66
+ );
67
+ }
68
+
26
69
/// Report any named fields in the record literal [node] that use a previously
27
70
/// defined name.
28
- void reportDuplicateFieldDefinitions (RecordLiteralImpl node) {
71
+ void _reportDuplicateFieldDefinitions (RecordLiteralImpl node) {
29
72
var usedNames = < String , NamedExpression > {};
30
73
for (var field in node.fields) {
31
74
if (field is NamedExpressionImpl ) {
@@ -43,7 +86,7 @@ class RecordLiteralResolver {
43
86
}
44
87
45
88
/// Report any fields in the record literal [node] that use an invalid name.
46
- void reportInvalidFieldNames (RecordLiteralImpl node) {
89
+ void _reportInvalidFieldNames (RecordLiteralImpl node) {
47
90
var fields = node.fields;
48
91
var positionalCount = 0 ;
49
92
for (var field in fields) {
@@ -74,49 +117,6 @@ class RecordLiteralResolver {
74
117
}
75
118
}
76
119
77
- void resolve (
78
- RecordLiteralImpl node, {
79
- required DartType ? contextType,
80
- }) {
81
- _resolveFields (node, contextType);
82
- _buildType (node, contextType);
83
-
84
- reportDuplicateFieldDefinitions (node);
85
- reportInvalidFieldNames (node);
86
- }
87
-
88
- void _buildType (RecordLiteralImpl node, DartType ? contextType) {
89
- final positionalFields = < RecordTypePositionalFieldImpl > [];
90
- final namedFields = < RecordTypeNamedFieldImpl > [];
91
- for (final field in node.fields) {
92
- final fieldType = field.typeOrThrow;
93
- if (field is NamedExpressionImpl ) {
94
- namedFields.add (
95
- RecordTypeNamedFieldImpl (
96
- name: field.name.label.name,
97
- type: fieldType,
98
- ),
99
- );
100
- } else {
101
- positionalFields.add (
102
- RecordTypePositionalFieldImpl (
103
- type: fieldType,
104
- ),
105
- );
106
- }
107
- }
108
-
109
- _resolver.inferenceHelper.recordStaticType (
110
- node,
111
- RecordTypeImpl (
112
- positionalFields: positionalFields,
113
- namedFields: namedFields,
114
- nullabilitySuffix: NullabilitySuffix .none,
115
- ),
116
- contextType: contextType,
117
- );
118
- }
119
-
120
120
void _resolveField (ExpressionImpl field, DartType ? contextType) {
121
121
_resolver.analyzeExpression (field, contextType);
122
122
field = _resolver.popRewrite ()! ;
@@ -128,6 +128,11 @@ class RecordLiteralResolver {
128
128
field.expression.staticType = contextType;
129
129
}
130
130
}
131
+
132
+ if (field.typeOrThrow is VoidType ) {
133
+ errorReporter.reportErrorForNode (
134
+ CompileTimeErrorCode .USE_OF_VOID_RESULT , field);
135
+ }
131
136
}
132
137
133
138
void _resolveFields (RecordLiteralImpl node, DartType ? contextType) {
0 commit comments