File tree 1 file changed +5
-6
lines changed
crates/jrsonnet-evaluator/src/evaluate
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ pub fn destruct(
170
170
#[ derive( Trace ) ]
171
171
struct DataThunk {
172
172
parent : Thunk < Val > ,
173
- field_names : Vec < IStr > ,
173
+ field_names : Vec < ( IStr , bool ) > ,
174
174
has_rest : bool ,
175
175
}
176
176
impl ThunkValue for DataThunk {
@@ -181,14 +181,14 @@ pub fn destruct(
181
181
let Val :: Obj ( obj) = v else {
182
182
bail ! ( "expected object" ) ;
183
183
} ;
184
- for field in & self . field_names {
185
- if !obj. has_field_ex ( field. clone ( ) , true ) {
184
+ for ( field, has_default ) in & self . field_names {
185
+ if !has_default && ! obj. has_field_ex ( field. clone ( ) , true ) {
186
186
bail ! ( "missing field: {field}" ) ;
187
187
}
188
188
}
189
189
if !self . has_rest {
190
190
let len = obj. len ( ) ;
191
- if len != self . field_names . len ( ) {
191
+ if len > self . field_names . len ( ) {
192
192
bail ! ( "too many fields, and rest not found" ) ;
193
193
}
194
194
}
@@ -197,8 +197,7 @@ pub fn destruct(
197
197
}
198
198
let field_names: Vec < _ > = fields
199
199
. iter ( )
200
- . filter ( |f| f. 2 . is_none ( ) )
201
- . map ( |f| f. 0 . clone ( ) )
200
+ . map ( |f| ( f. 0 . clone ( ) , f. 2 . is_some ( ) ) )
202
201
. collect ( ) ;
203
202
let full = Thunk :: new ( DataThunk {
204
203
parent,
You can’t perform that action at this time.
0 commit comments