rusty icon indicating copy to clipboard operation
rusty copied to clipboard

function block call - "output is not a STRING"

Open rarris opened this issue 1 year ago • 2 comments

PROGRAM mainProg
VAR
   fb1 : function_block_0;
END_VAR
   fb1(
     input1 := IN1,
     output => OUT1
   );
END_PROGRAM

FUNCTION_BLOCK function_block_0
VAR_INPUT
  input1 : inDATA;
END_VAR
VAR_OUTPUT
  output : outDATA;
END_VAR
VAR
END_VAR
;
END_FUNCTION_BLOCK

TYPE inDATA :
 STRUCT
	  Id:UDINT;
 END_STRUCT
END_TYPE

TYPE outDATA :
 STRUCT
  	  Parm:UDINT;
 END_STRUCT
END_TYPE

VAR_GLOBAL
  IN1 : inDATA;
  OUT1 : outDATA;
END_VAR

mainProg.st:7:12:{7:12-7:16}: error[E071]: outDATA is not a String Error: Compilation aborted due to previous errors

rarris avatar Mar 19 '24 09:03 rarris

I have reduced the reproducible example down a little:

TYPE OUT_TYPE : STRUCT 
    a : BYTE;
END_STRUCT;
END_TYPE

FUNCTION_BLOCK FB
VAR_OUTPUT 
    output : OUT_TYPE;
END_VAR    
END_FUNCTION_BLOCK

PROGRAM PRG
VAR
    out: OUT_TYPE;
    station: FB;
END_VAR
    station(output => out);
END_PROGRAM

mhasel avatar Mar 21 '24 15:03 mhasel

This happens here: https://github.com/PLC-lang/rusty/blob/b357a05cb064eb21fed110b6d7c5f543f72c18e8/src/codegen/generators/expression_generator.rs#L574-L579

generate_string_store then expects a string and will fail on any other type. Simply commenting out the ORed conditions for structs and arrays will get rid of the error. Structs and arrays will then be generated via stores, so maybe related to #1074 too. I might be missing something here - do we need special handling for arrays and structs (i.e. all aggregate types) in output assignments? The comment only mentions strings.

mhasel avatar Mar 25 '24 09:03 mhasel