@@ -130,6 +130,28 @@ impl<'source, 'temp, 'out> super::ExpressionContext<'source, 'temp, 'out> {
130
130
Ok ( ( ) )
131
131
}
132
132
133
+ /// Convert `expr` to the leaf scalar type `scalar`.
134
+ pub fn convert_to_leaf_scalar (
135
+ & mut self ,
136
+ expr : & mut Handle < crate :: Expression > ,
137
+ goal : crate :: Scalar ,
138
+ ) -> Result < ( ) , super :: Error < ' source > > {
139
+ let inner = super :: resolve_inner!( self , * expr) ;
140
+ // Do nothing if `inner` doesn't even have leaf scalars;
141
+ // it's a type error that validation will catch.
142
+ if inner. scalar ( ) != Some ( goal) {
143
+ let cast = crate :: Expression :: As {
144
+ expr : * expr,
145
+ kind : goal. kind ,
146
+ convert : Some ( goal. width ) ,
147
+ } ;
148
+ let expr_span = self . get_expression_span ( * expr) ;
149
+ * expr = self . append_expression ( cast, expr_span) ?;
150
+ }
151
+
152
+ Ok ( ( ) )
153
+ }
154
+
133
155
/// Convert all expressions in `exprs` to a common scalar type.
134
156
///
135
157
/// Note that the caller is responsible for making sure these
@@ -146,18 +168,7 @@ impl<'source, 'temp, 'out> super::ExpressionContext<'source, 'temp, 'out> {
146
168
goal : crate :: Scalar ,
147
169
) -> Result < ( ) , super :: Error < ' source > > {
148
170
for expr in exprs. iter_mut ( ) {
149
- let inner = super :: resolve_inner!( self , * expr) ;
150
- // Do nothing if `inner` doesn't even have leaf scalars;
151
- // it's a type error that validation will catch.
152
- if inner. scalar ( ) != Some ( goal) {
153
- let cast = crate :: Expression :: As {
154
- expr : * expr,
155
- kind : goal. kind ,
156
- convert : Some ( goal. width ) ,
157
- } ;
158
- let expr_span = self . get_expression_span ( * expr) ;
159
- * expr = self . append_expression ( cast, expr_span) ?;
160
- }
171
+ self . convert_to_leaf_scalar ( expr, goal) ?;
161
172
}
162
173
163
174
Ok ( ( ) )
0 commit comments