Skip to content

Typecheck fn calls - #79

Merged
mikucionisaau merged 7 commits into
UPPAALModelChecker:mainfrom
mikucionisaau:typecheck-fn-calls
Aug 3, 2026
Merged

Typecheck fn calls#79
mikucionisaau merged 7 commits into
UPPAALModelChecker:mainfrom
mikucionisaau:typecheck-fn-calls

Conversation

@mikucionisaau

@mikucionisaau mikucionisaau commented Feb 14, 2025

Copy link
Copy Markdown
Member

Improves error reporting when fn call arguments do not match the function parameters.

mikucionisaau and others added 5 commits October 1, 2024 08:35
checkExpression's too-few-arguments guard compared the loop index
against expr.get_size() while indexing arguments with expr[i+1],
so it either never fired (missing exactly one argument) or fired
one iteration too late, tripping the out-of-bounds assert in
Expression::operator[] first. Only reachable via query type-checking,
since top-level document parsing skips TypeChecker once
ExpressionBuilder has already recorded a "too few arguments" error.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
visit_variable() called checkInitialiser() but never assigned the
returned Expression back to variable.init, so global/const struct
initialisers with out-of-order named fields kept their raw parse-order
sub-expressions instead of being reordered to match field declaration
order (visit_block_statement already did this correctly for locals).

Separately, checkInitialiser's array branch called itself recursively
per element but never stored the result in result[i], leaving the
returned LIST full of empty sub-expressions whenever an array element
needed coercion/reordering (e.g. array of structs with named fields).
This was masked for globals by the bug above, but corrupted local
array-of-struct initialisers via visit_block_statement.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mikucionisaau
mikucionisaau marked this pull request as ready for review August 3, 2026 13:04
mikucionisaau and others added 2 commits August 3, 2026 13:22
…rrors

The struct/array initialisation tests in parser_test.cpp only asserted
that no errors/warnings were produced, never inspecting the resulting
Variable::init expression. That meant none of them would have caught
the two checkInitialiser bugs just fixed: they compared equal whether
checkInitialiser's rewritten (correctly typed/reordered) result was
kept or silently discarded.

Add assertions that the initialiser carries the variable's exact
declared type (label/const/meta/range annotations, which only appear
once checkInitialiser's return value is actually used) and that each
field/element holds the expected value. Verified these now fail
against the pre-fix TypeChecker.cpp (13 of the strengthened cases
regress) and pass against the fix.

Also drops an exact duplicate "Meta field in non meta struct" test case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Matches the existing get_templates() pattern. Lets read-only helpers
take a const Document& instead of requiring mutable access just to
read global declarations.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mikucionisaau
mikucionisaau merged commit b5fe3b2 into UPPAALModelChecker:main Aug 3, 2026
8 checks passed
@mikucionisaau
mikucionisaau deleted the typecheck-fn-calls branch August 3, 2026 13:32
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.

1 participant