@@ -2,7 +2,7 @@ use std::collections::HashMap;
22use std:: fmt;
33use std:: sync:: Arc ;
44
5- use crate :: error:: { Diagnostic , Error , WithSpan } ;
5+ use crate :: error:: { Diagnostic , DiagnosticManager , Error , WithSpan } ;
66use crate :: parse:: ParseFromStr ;
77use crate :: str:: WitnessName ;
88use crate :: types:: { AliasedType , ResolvedType } ;
@@ -110,23 +110,25 @@ impl WitnessValues {
110110 /// There may be witnesses that are referenced in the program that are not assigned a value
111111 /// in the witness map. These witnesses may lie on pruned branches that will not be part of the
112112 /// finalized Simplicity program. However, before the finalization, we cannot know which
113- /// witnesses will be pruned and which won't be pruned. This check skips unassigned witnesses.
114- pub fn is_consistent ( & self , witness_types : & WitnessTypes ) -> Result < ( ) , Error > {
115- for name in self . 0 . keys ( ) {
116- let Some ( declared_ty) = witness_types. get ( name) else {
113+ /// witnesses will be pruned and which won't be pruned.
114+ pub fn is_consistent ( & self , witness_types : & WitnessTypes , diagnostics : & mut DiagnosticManager ) {
115+ for ( name, declared_ty) in witness_types. iter ( ) {
116+ let Some ( value) = self . get ( name) else {
117+ diagnostics. push ( Diagnostic :: global ( Error :: WitnessMissing {
118+ name : name. shallow_clone ( ) ,
119+ } ) ) ;
117120 continue ;
118121 } ;
119- let assigned_ty = self . 0 [ name] . ty ( ) ;
122+
123+ let assigned_ty = value. ty ( ) ;
120124 if assigned_ty != declared_ty {
121- return Err ( Error :: WitnessTypeMismatch {
125+ diagnostics . push ( Diagnostic :: global ( Error :: WitnessTypeMismatch {
122126 name : name. clone ( ) ,
123127 declared : declared_ty. clone ( ) ,
124128 assigned : assigned_ty. clone ( ) ,
125- } ) ;
129+ } ) ) ;
126130 }
127131 }
128-
129- Ok ( ( ) )
130132 }
131133}
132134
@@ -234,21 +236,23 @@ impl Arguments {
234236 /// 2. The type of each parameter must match the type of its argument.
235237 ///
236238 /// Arguments without a corresponding parameter are ignored.
237- pub fn is_consistent ( & self , parameters : & Parameters ) -> Result < ( ) , Error > {
239+ pub fn is_consistent ( & self , parameters : & Parameters , diagnostics : & mut DiagnosticManager ) {
238240 for ( name, parameter_ty) in parameters. iter ( ) {
239- let argument = self . get ( name) . ok_or_else ( || Error :: ArgumentMissing {
240- name : name. shallow_clone ( ) ,
241- } ) ?;
241+ let Some ( argument) = self . get ( name) else {
242+ diagnostics. push ( Diagnostic :: global ( Error :: ArgumentMissing {
243+ name : name. shallow_clone ( ) ,
244+ } ) ) ;
245+ continue ;
246+ } ;
247+
242248 if !argument. is_of_type ( parameter_ty) {
243- return Err ( Error :: ArgumentTypeMismatch {
249+ diagnostics . push ( Diagnostic :: global ( Error :: ArgumentTypeMismatch {
244250 name : name. clone ( ) ,
245251 declared : parameter_ty. clone ( ) ,
246252 assigned : argument. ty ( ) . clone ( ) ,
247- } ) ;
253+ } ) ) ;
248254 }
249255 }
250-
251- Ok ( ( ) )
252256 }
253257}
254258
@@ -313,7 +317,7 @@ mod tests {
313317 ) {
314318 Ok ( _) => panic ! ( "Ill-typed witness assignment was falsely accepted" ) ,
315319 Err ( error) => assert_eq ! (
316- "Witness `A` was declared with type `u32` but its assigned value is of type `u16`" ,
320+ "Witness `A` was declared with type `u32` but its assigned value is of type `u16`\n " ,
317321 error
318322 ) ,
319323 }
0 commit comments