Skip to content

Commit 146e5f9

Browse files
authored
fix: Handle generics with no return type (#1484)
The following code example will panic on master because we except a return type to be present. However, with #1103 this is no longer the case. This commit fixes the issue by assigning a `VOID` datatype if the index was not able to find a return type for generics. ``` FUNCTION genericVoidFunction<U: ANY> VAR_INPUT in : U; END_VAR END_FUNCTION FUNCTION main VAR localVar : DINT; END_VAR genericVoidFunction(localVar); END_FUNCTION ```
1 parent 2bb7720 commit 146e5f9

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/resolver/generics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ impl TypeAnnotator<'_> {
143143
generic_implementation.get_location().to_owned(),
144144
);
145145

146-
let return_type =
147-
self.index.find_type(return_type_name).expect("Return type must be in the index");
146+
let return_type = self.index.find_type(return_type_name).unwrap_or(self.index.get_void_type());
148147
//register a copy of the pou under the new name
149148
self.annotation_map.new_index.register_pou(PouIndexEntry::create_generated_function_entry(
150149
new_name,

0 commit comments

Comments
 (0)