@@ -5960,7 +5960,45 @@ fn global_namespace_operator_is_not_resolved() {
5960
5960
}
5961
5961
5962
5962
#[ test]
5963
- fn is_this_there ( ) {
5963
+ fn this_in_assignments_in_methods ( ) {
5964
+ let id_provider = IdProvider :: default ( ) ;
5965
+ let ( unit, mut index) = index_with_ids (
5966
+ "
5967
+ FUNCTION_BLOCK fb
5968
+ VAR
5969
+ myvar : INT;
5970
+ END_VAR
5971
+ METHOD foo : INT
5972
+ this^.myvar := 8;
5973
+ myvar := this^.myvar;
5974
+ END_FUNCTION_BLOCK
5975
+ END_FUNCTION_BLOCK
5976
+ " ,
5977
+ id_provider. clone ( ) ,
5978
+ ) ;
5979
+
5980
+ let annotations = annotate_with_ids ( & unit, & mut index, id_provider) ;
5981
+ let AstStatement :: Assignment ( statement_1) = unit. implementations [ 0 ] . statements [ 0 ] . get_stmt ( ) else {
5982
+ unreachable ! ( )
5983
+ } ;
5984
+ let AstStatement :: Assignment ( statement_2) = unit. implementations [ 0 ] . statements [ 1 ] . get_stmt ( ) else {
5985
+ unreachable ! ( )
5986
+ } ;
5987
+ assert ! ( index. find_type( "fb.__THIS" ) . is_some( ) ) ;
5988
+ assert_type_and_hint ! ( & annotations, & index, & statement_1. left, "INT" , None ) ;
5989
+ assert_type_and_hint ! ( & annotations, & index, & statement_2. right, "INT" , Some ( "INT" ) ) ;
5990
+ let AstStatement :: ReferenceExpr ( ReferenceExpr { base : Some ( deref) , .. } ) = statement_1. left . get_stmt ( )
5991
+ else {
5992
+ unreachable ! ( ) ;
5993
+ } ;
5994
+ let AstStatement :: ReferenceExpr ( ReferenceExpr { base : Some ( this) , .. } ) = deref. get_stmt ( ) else {
5995
+ unreachable ! ( ) ;
5996
+ } ;
5997
+ assert_type_and_hint ! ( & annotations, & index, this, "fb.__THIS" , None ) ;
5998
+ }
5999
+
6000
+ #[ test]
6001
+ fn this_in_assignments ( ) {
5964
6002
let id_provider = IdProvider :: default ( ) ;
5965
6003
let ( unit, mut index) = index_with_ids (
5966
6004
"
@@ -6131,5 +6169,71 @@ fn this_call() {
6131
6169
let statement = & unit. implementations [ 0 ] . statements [ 0 ] ;
6132
6170
dbg ! ( & statement) ;
6133
6171
assert ! ( index. find_type( "fb.__THIS" ) . is_some( ) ) ;
6134
- assert_type_and_hint ! ( & annotations, & index, statement, "fb.__THIS" , None ) ;
6172
+ // assert_type_and_hint!(&annotations, &index, statement, "fb.__THIS", None);
6173
+ }
6174
+
6175
+ #[ test]
6176
+ fn this_as_function_parameter ( ) {
6177
+ let id_provider = IdProvider :: default ( ) ;
6178
+ let ( unit, mut index) = index_with_ids (
6179
+ "
6180
+ FUNCTION_BLOCK FB_Test
6181
+ foo2(this);
6182
+ END_FUNCTION_BLOCK
6183
+ " ,
6184
+ id_provider. clone ( ) ,
6185
+ ) ;
6186
+
6187
+ let annotations = annotate_with_ids ( & unit, & mut index, id_provider) ;
6188
+ let statement = & unit. implementations [ 0 ] . statements [ 0 ] ;
6189
+ let AstStatement :: CallStatement ( CallStatement { parameters : Some ( param) , .. } ) = statement. get_stmt ( )
6190
+ else {
6191
+ unreachable ! ( ) ;
6192
+ } ;
6193
+ let Some ( StatementAnnotation :: Value { resulting_type, .. } ) = annotations. get ( param) else {
6194
+ unreachable ! ( )
6195
+ } ;
6196
+ assert_eq ! ( resulting_type, "FB_Test.__THIS" ) ;
6197
+ assert ! ( index. find_type( "fb_test.__THIS" ) . is_some( ) ) ;
6198
+ }
6199
+
6200
+ #[ test]
6201
+ fn this_in_conditionals ( ) {
6202
+ let id_provider = IdProvider :: default ( ) ;
6203
+ let ( unit, mut index) = index_with_ids (
6204
+ "
6205
+ FUNCTION_BLOCK FB_Test
6206
+ VAR
6207
+ x : INT;
6208
+ bo: BOOL;
6209
+ END_VAR
6210
+ IF this^.bo THEN
6211
+ x := 1;
6212
+ END_IF
6213
+ END_FUNCTION_BLOCK
6214
+ " ,
6215
+ id_provider. clone ( ) ,
6216
+ ) ;
6217
+
6218
+ let annotations = annotate_with_ids ( & unit, & mut index, id_provider) ;
6219
+ let statement = & unit. implementations [ 0 ] . statements [ 0 ] ;
6220
+ let AstStatement :: ControlStatement ( AstControlStatement :: If ( IfStatement { blocks, .. } ) ) =
6221
+ unit. implementations [ 0 ] . statements [ 0 ] . get_stmt ( )
6222
+ else {
6223
+ unreachable ! ( ) ;
6224
+ } ;
6225
+ let AstStatement :: ReferenceExpr ( ReferenceExpr { base : Some ( deref) , .. } ) = blocks[ 0 ] . condition . get_stmt ( )
6226
+ else {
6227
+ unreachable ! ( ) ;
6228
+ } ;
6229
+ let AstStatement :: ReferenceExpr ( ReferenceExpr { base : Some ( base) , .. } ) = deref. get_stmt ( ) else {
6230
+ unreachable ! ( )
6231
+ } ;
6232
+ let StatementAnnotation :: Value { resulting_type, .. } = annotations. get ( base) . expect ( "damn" ) else {
6233
+ unreachable ! ( )
6234
+ } ;
6235
+ assert_eq ! ( resulting_type, "FB_Test.__THIS" ) ;
6236
+ dbg ! ( resulting_type) ;
6237
+ // dbg!(&statement);
6238
+ assert ! ( index. find_type( "fb_test.__THIS" ) . is_some( ) ) ;
6135
6239
}
0 commit comments