Skip to content

Commit d3f789b

Browse files
committed
fix a bug with signature agreement checking
1 parent 2fc4043 commit d3f789b

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/compile/binding.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,6 @@ impl Compiler {
234234
// Resolve signature
235235
match instrs_signature(&instrs) {
236236
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-
259237
#[rustfmt::skip]
260238
let is_setinv = matches!(
261239
instrs.as_slice(),
@@ -275,6 +253,7 @@ impl Compiler {
275253
func.id = FunctionId::Named(name.clone());
276254
func
277255
};
256+
sig = f.signature();
278257
self.compile_bind_function(&name, local, func, spandex, comment.as_deref())?;
279258
} else if sig == (0, 1) && !is_setinv && !is_setund {
280259
if let &[Instr::Prim(Primitive::Tag, span)] = instrs.as_slice() {
@@ -327,8 +306,8 @@ impl Compiler {
327306
Ok(height) => {
328307
if *height > 0 {
329308
sig = Signature::new(0, 1);
309+
*height -= 1;
330310
}
331-
*height = height.saturating_sub(1);
332311
}
333312
Err(sp) => {
334313
let sp = sp.clone();
@@ -376,6 +355,19 @@ impl Compiler {
376355
self.compile_bind_function(&name, local, func, spandex, comment.as_deref())?;
377356
}
378357

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+
379371
self.code_meta.function_sigs.insert(
380372
words_span,
381373
SigDecl {

tests/signature.ua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
B ← |0.0
12
# Parens
23
F ← |1 ×.
34
F ← |1 (×.)

0 commit comments

Comments
 (0)