Skip to content

[WIP] Typecheck procedure signatures + Various changes#1420

Open
Pieter12345 wants to merge 11 commits into
EngineHub:masterfrom
Pieter12345:typecheck-proc-signatures
Open

[WIP] Typecheck procedure signatures + Various changes#1420
Pieter12345 wants to merge 11 commits into
EngineHub:masterfrom
Pieter12345:typecheck-proc-signatures

Conversation

@Pieter12345

@Pieter12345 Pieter12345 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Typecheck procedure signatures. This assumes that procedure signatures cannot be redefined after the initial declaration, which does not hold for the current implementation. Enforcing this should be done at a later point as this potentially breaks user scripts.
  • Disallow mandatory-after-optional params in proc signature typechecking.
  • Prevent injected @arguments variable overwriting an explicitly declared procedure parameter named @arguments.
  • Initialize procedure varargs parameter with an empty array if it matches no arguments. Prevents varargs parameter value being CNull.UNDEFINED when it has no matching arguments.
  • Add compile error on missing returns in procedures.
  • Implement function signatures and getReturnType() in control flow manipulating functions.
  • Throw exception when invoking proc forward declaration (opposed to not doing anything and returning void, regardless of the declared proc return type).
  • Add none type and missing return false error tests. These ensure that mentioned typechecking and missing return error changes do not break the obvious use-cases that can be expected to be affected.
  • Implement function signature none type allowed boolean per Param instead of per FunctionSignature. This is reflected in the function signatures string.
  • Apply none type allowed boolean in FunctionSignature to all type of Param instead of only to varparams.
  • Update function signatures of dand() and dor(). Fixes NPE when calling dor() without arguments (given that SA is enabled).

WIP

This PR is marked as work-in-progress for the following reasons that should be addressed before merging:

  • dor() and dand() typechecking implementation needs to be implemented in order to prevent missing return errors for returns within them that are guaranteed to run.
  • This PR should be tested against large code bases to identify potentially undesired breaking changes.

- Prevent injected `@arguments` variable overwriting an explicitly declared procedure parameter named `@arguments`.
- Initialize procedure varargs parameter with an empty array if it matches no arguments. Prevents varargs parameter value being `CNull.UNDEFINED` when it has no matching arguments.
Generate compile error for missing return statements in any code path of non-void procedure code.
- Forward `null` return type during typechecking when the function won't return at all.
- Return least specific type among possible return types in control flow functions with multiple possible outcomes. These essentially need to return a multi-type CClassType, but this is the best we can do in the current code base without introducing harm.
- Implement function signature none type allowed boolean per Param instead of per FunctionSignature. This is reflected in the function signatures string.
- Apply none type allowed boolean to all type of Param instead of only to varparams.
- Update function signatures of `dand()` and `dor()`. Fixes NPE when calling `dor()` without arguments (given that SA is enabled).
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