@@ -234,28 +234,6 @@ impl Compiler {
234
234
// Resolve signature
235
235
match instrs_signature ( & instrs) {
236
236
Ok ( mut sig) => {
237
- // Validate signature
238
- if let Some ( declared_sig) = & binding. signature {
239
- let sig_to_check = if let [ Instr :: PushFunc ( f) ] = instrs. as_slice ( ) {
240
- // If this is a function wrapped in parens, check the signature of the
241
- // function rather than the signature of the binding's words
242
- f. signature ( )
243
- } else if instrs. is_empty ( ) {
244
- Signature :: new ( 0 , 1 )
245
- } else {
246
- sig
247
- } ;
248
- if declared_sig. value != sig_to_check {
249
- self . add_error (
250
- declared_sig. span . clone ( ) ,
251
- format ! (
252
- "Function signature mismatch: declared {} but inferred {}" ,
253
- declared_sig. value, sig_to_check
254
- ) ,
255
- ) ;
256
- }
257
- }
258
-
259
237
#[ rustfmt:: skip]
260
238
let is_setinv = matches ! (
261
239
instrs. as_slice( ) ,
@@ -275,6 +253,7 @@ impl Compiler {
275
253
func. id = FunctionId :: Named ( name. clone ( ) ) ;
276
254
func
277
255
} ;
256
+ sig = f. signature ( ) ;
278
257
self . compile_bind_function ( & name, local, func, spandex, comment. as_deref ( ) ) ?;
279
258
} else if sig == ( 0 , 1 ) && !is_setinv && !is_setund {
280
259
if let & [ Instr :: Prim ( Primitive :: Tag , span) ] = instrs. as_slice ( ) {
@@ -327,8 +306,8 @@ impl Compiler {
327
306
Ok ( height) => {
328
307
if * height > 0 {
329
308
sig = Signature :: new ( 0 , 1 ) ;
309
+ * height -= 1 ;
330
310
}
331
- * height = height. saturating_sub ( 1 ) ;
332
311
}
333
312
Err ( sp) => {
334
313
let sp = sp. clone ( ) ;
@@ -376,6 +355,19 @@ impl Compiler {
376
355
self . compile_bind_function ( & name, local, func, spandex, comment. as_deref ( ) ) ?;
377
356
}
378
357
358
+ // Validate signature
359
+ if let Some ( declared_sig) = & binding. signature {
360
+ if declared_sig. value != sig {
361
+ self . add_error (
362
+ declared_sig. span . clone ( ) ,
363
+ format ! (
364
+ "Function signature mismatch: declared {} but inferred {}" ,
365
+ declared_sig. value, sig
366
+ ) ,
367
+ ) ;
368
+ }
369
+ }
370
+
379
371
self . code_meta . function_sigs . insert (
380
372
words_span,
381
373
SigDecl {
0 commit comments