File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -2256,3 +2256,36 @@ fn inheritance_chain_correctly_finds_parents() {
2256
2256
let inheritance_chain = index. get_inheritance_chain ( "grandparent" , "child" ) ;
2257
2257
assert_eq ! ( inheritance_chain, Vec :: <& PouIndexEntry >:: new( ) ) ;
2258
2258
}
2259
+
2260
+ #[ test]
2261
+ fn pou_with_two_types_not_consireded_recursive ( ) {
2262
+ let ( _, index) = index (
2263
+ "
2264
+ FUNCTION_BLOCK fb
2265
+ VAR x,y : DINT; END_VAR
2266
+ END_FUNCTION_BLOCK
2267
+ PROGRAM p
2268
+ VAR
2269
+ x : fb;
2270
+ y : fb;
2271
+ END_VAR
2272
+ END_PROGRAM" ,
2273
+ ) ;
2274
+
2275
+ let pou_type = index. find_pou_type ( "p" ) . unwrap ( ) ;
2276
+ assert_eq ! ( pou_type. get_type_information( ) . get_size( & index) . unwrap( ) . bits( ) , 128 ) ;
2277
+ }
2278
+
2279
+ #[ test]
2280
+ fn pou_with_recursive_type_fails ( ) {
2281
+ let ( _, index) = index (
2282
+ "
2283
+ FUNCTION_BLOCK fb
2284
+ VAR x : fb; END_VAR
2285
+ END_FUNCTION_BLOCK
2286
+ " ,
2287
+ ) ;
2288
+
2289
+ let pou_type = index. find_pou_type ( "fb" ) . unwrap ( ) ;
2290
+ assert ! ( pou_type. get_type_information( ) . get_size( & index) . is_err( ) ) ;
2291
+ }
Original file line number Diff line number Diff line change @@ -631,7 +631,7 @@ impl DataTypeInformation {
631
631
if self . is_struct ( ) && !seen. insert ( self . get_name ( ) ) {
632
632
return Err ( anyhow ! ( "Recursive type detected: {}" , self . get_name( ) ) ) ;
633
633
}
634
- match self {
634
+ let res = match self {
635
635
DataTypeInformation :: Integer { size, .. } => Ok ( Bytes :: from_bits ( * size) ) ,
636
636
DataTypeInformation :: Float { size, .. } => Ok ( Bytes :: from_bits ( * size) ) ,
637
637
DataTypeInformation :: String { size, encoding } => Ok ( size
@@ -668,7 +668,9 @@ impl DataTypeInformation {
668
668
. map ( |it| it. get_size ( index) )
669
669
. unwrap_or_else ( || Ok ( Bytes :: from_bits ( DINT_SIZE ) ) ) ,
670
670
DataTypeInformation :: Generic { .. } | DataTypeInformation :: Void => Ok ( Bytes :: from_bits ( 0 ) ) ,
671
- }
671
+ } ;
672
+ seen. remove ( self . get_name ( ) ) ;
673
+ res
672
674
}
673
675
674
676
/// Returns the String encoding's alignment (character)
You can’t perform that action at this time.
0 commit comments