PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
223 stars 53 forks source link

feat: Validate required `INPUT` and `IN_OUT` arguments for methods #1364

Open volsa opened 6 days ago

volsa commented 6 days ago

This commit introduces a validation which makes sure that INPUT and IN_OUT arguments are present for methods and if not yields a diagnostic.

mhasel commented 6 days ago
FUNCTION_BLOCK foo
VAR_INPUT 
    x : DINT := 34;
END_VAR
METHOD bar 
VAR_INPUT 
    x : DINT := 34;
END_VAR
END_METHOD
END_FUNCTION_BLOCK 

FUNCTION baz
VAR_INPUT 
    x : DINT := 34;
END_VAR
END_FUNCTION

FUNCTION main : DINT 
VAR 
    fb: foo;
END_VAR
    fb.bar();
    baz();
END_FUNCTION

Both the calls to fb.bar and baz have the same error, yet yield different diagnostics:

error[E030]: Argument `x` is missing
   ┌─ target/demo.st:22:5
   │
22 │     fb.bar();
   │     ^^^^^^ Argument `x` is missing

error[E032]: this POU takes 1 argument but 0 arguments were supplied
   ┌─ target/demo.st:23:5
   │
23 │     baz();
   │     ^^^ this POU takes 1 argument but 0 arguments were supplied

Compilation aborted due to critical errors.