Skip to content

fix: swap Too many/Too few messages and correct expected/have in callback arg errors (#42)#1564

Open
KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
KorsarOfficial:bugfix/issue-42-callback-error-messages
Open

fix: swap Too many/Too few messages and correct expected/have in callback arg errors (#42)#1564
KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
KorsarOfficial:bugfix/issue-42-callback-error-messages

Conversation

@KorsarOfficial
Copy link

Problem

The two error messages for callback argument count mismatches in check-func-calls-and-vararg.cpp had their labels swapped and the expected/have format arguments transposed.

Formal Analysis

Define argument validation predicates:

n   = actual argument count    (call_n_params)
min = minimum required args    (f->get_min_argn())
max = maximum allowed args     (f->get_params().size())

P_min(n) := n >= min    (sufficient arguments)
P_max(n) := n <= max    (not excessive arguments)

Error mapping:
  not P_min(n) => "Too few arguments"    (n < min)
  not P_max(n) => "Too many arguments"   (n > max)

Bug — two compound errors:

Condition Old (wrong) New (correct)
n < min (too few) "Too many, exp=n, have=min" "Too few, exp=min, have=n"
n > max (too many) "Too few, exp=n, have=max" "Too many, exp=max, have=n"

Truth table (min=2, max=4):

n Condition Old output Correct output
1 n < min "Too many, exp=1, have=2" "Too few, exp=2, have=1"
3 valid (no error) (no error)
5 n > max "Too few, exp=5, have=4" "Too many, exp=4, have=5"

Fix

Swap message strings and reorder fmt_format arguments to match the non-callback pattern on lines 271-274 (known correct reference).

Verification: After fix, callback error structure is isomorphic to the non-callback pattern:

non-callback:  kphp_error(n >= min, "Too few ..., exp=min, have=n")
callback:      kphp_error(n >= min, "Too few ..., exp=min-d, have=n-d")
                                                    ^^^^^^^^^^^^^^^^^^^^
                                              identical modulo delta offset

Technical Report

Full report with mathematical formalization (PDF)

Closes #42

…callback arg errors (VKCOM#42)

The two error messages for callback argument count mismatches in
check-func-calls-and-vararg.cpp had their labels swapped and their
printf arguments in the wrong order:

  - The condition `call_n_params >= get_min_argn()` is false when there
    are TOO FEW arguments, but the message said "Too many arguments for
    callback".
  - The condition `get_params().size() >= call_n_params` is false when
    there are TOO MANY arguments, but the message said "Too few arguments
    for callback".
  - In both cases the "expected" and "have" values were transposed.

Fix: swap the two message strings and swap the fmt_format arguments to
match the corrected messages and mirror the non-callback pattern on
lines 271-274.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing error for the method implementation with mismatching param name

1 participant