@@ -162,7 +162,7 @@ public void visit(AssignmentStatement assignmentStatement) {
162
162
if (valueType instanceof EolModelElementType && ((EolModelElementType ) valueType ).getMetaClass () != null )
163
163
valueType = new EolModelElementType (((EolModelElementType ) valueType ).getMetaClass ());
164
164
165
- if (!( isCompatible ( targetType , valueType ) )) {
165
+ if (!targetType . isAncestorOf ( valueType )) {
166
166
if (canBeCompatible (targetType , valueType )) {
167
167
createTypeCompatibilityWarning (targetExpression , valueExpression );
168
168
}
@@ -739,29 +739,31 @@ public void visit(OperationCallExpression operationCallExpression) {
739
739
for (IStaticOperation op : resolvedOperations ) {
740
740
resolvedOperationContextTypes .add (op .getContextType ());
741
741
}
742
-
742
+
743
+ // If the contextType is a UnionType all containedTypes must be handled
743
744
if (contextType instanceof EolUnionType ) {
744
- if (resolvedOperationContextTypes .containsAll (((EolUnionType )contextType ).containedTypes )){
745
- return ;
746
- }
747
- }
748
- else {
749
- if (resolvedOperationContextTypes .contains (contextType )) {
750
- return ;
751
- }
752
- }
753
-
754
- // TODO: get descendants?
755
- for (EolType t : contextType .getChildrenTypes ()) {
756
- if (!resolvedOperationContextTypes .contains (t )) {
745
+ outerLoop : for (EolType t : ((EolUnionType ) contextType ).containedTypes ) {
746
+ for (EolType a : t .getAncestors ()) {
747
+ if (resolvedOperationContextTypes .contains (a )) {
748
+ continue outerLoop ;
749
+ }
750
+ }
757
751
warnings .add (
758
752
new ModuleMarker (
759
753
operationCallExpression , "Operation " + nameExpression .getName ()
760
754
+ " is undefined for subtype " + t .getName () + " of " + contextType .getName (),
761
755
Severity .Warning ));
762
756
}
757
+ } else {
758
+ for (EolType a : contextType .getAncestors ()) {
759
+ if (resolvedOperationContextTypes .contains (a )) {
760
+ return ;
761
+ }
762
+ }
763
+ warnings .add (new ModuleMarker (operationCallExpression ,
764
+ "Operation " + nameExpression .getName () + " is undefined for type " + contextType .getName (),
765
+ Severity .Warning ));
763
766
}
764
-
765
767
}
766
768
767
769
@ Override
@@ -936,7 +938,7 @@ public void visit(ReturnStatement returnStatement) {
936
938
setReturnFlag (((Operation ) parent ), true );
937
939
EolType requiredReturnType = (EolType ) parent .getData ().get ("returnType" );
938
940
939
- if (!( isCompatible ( requiredReturnType , providedReturnType ) )) {
941
+ if (!requiredReturnType . isAncestorOf ( providedReturnType )) {
940
942
if (canBeCompatible (requiredReturnType , providedReturnType ))
941
943
warnings .add (new ModuleMarker (returnedExpression , "Return type might be " + requiredReturnType
942
944
+ " instead of " + getResolvedType (returnedExpression ), Severity .Warning ));
@@ -1277,73 +1279,6 @@ public void createTypeCompatibilityError(Expression requiredExpression, Expressi
1277
1279
Severity .Error ));
1278
1280
}
1279
1281
1280
- public boolean isCompatible (EolType targetType , EolType valueType ) {
1281
-
1282
- if (targetType .equals (EolNoType .Instance ) || valueType .equals (EolNoType .Instance )) {
1283
- return false ;
1284
- }
1285
-
1286
- if (valueType instanceof EolUnionType ) {
1287
- for (EolType t : ((EolUnionType )valueType ).containedTypes ) {
1288
- while (true ) {
1289
- if (t instanceof EolAnyType ) {
1290
- return false ;
1291
- }
1292
- if (!t .equals (targetType )) {
1293
- t = getParentType (t );
1294
- } else {
1295
- break ;
1296
- }
1297
- }
1298
- }
1299
- return true ;
1300
- }
1301
-
1302
- while (true ) {
1303
- if (!(targetType .equals (valueType )) && !(targetType instanceof EolAnyType )) {
1304
-
1305
- if (valueType instanceof EolAnyType ) {
1306
- return false ;
1307
- }
1308
-
1309
- valueType = getParentType (valueType );
1310
-
1311
- } else if (targetType instanceof EolAnyType ) {
1312
- return true ;
1313
- } else if (valueType instanceof EolCollectionType
1314
- && !((((EolCollectionType ) targetType ).getContentType ()) instanceof EolAnyType )) {
1315
-
1316
- EolType valueContentType = ((EolCollectionType ) valueType ).getContentType ();
1317
- EolType targetContentType = ((EolCollectionType ) targetType ).getContentType ();
1318
-
1319
- while (targetContentType instanceof EolCollectionType
1320
- && valueContentType instanceof EolCollectionType ) {
1321
- if (targetContentType .equals (valueContentType )) {
1322
- return isCompatible (((EolCollectionType ) targetContentType ).getContentType (),
1323
- ((EolCollectionType ) valueContentType ).getContentType ());
1324
- } else {
1325
- valueContentType = getParentType (valueContentType );
1326
- return isCompatible (targetContentType , valueContentType );
1327
-
1328
- }
1329
- }
1330
- while (true ) {
1331
- if (valueContentType instanceof EolAnyType ) {
1332
- return false ;
1333
- }
1334
- if (!valueContentType .equals (targetContentType )) {
1335
- valueContentType = getParentType (valueContentType );
1336
- } else {
1337
- return true ;
1338
- }
1339
- }
1340
- }else {
1341
- return true ;
1342
- }
1343
-
1344
- }
1345
- }
1346
-
1347
1282
public boolean canBeCompatible (EolType targetType , EolType valueType ) {
1348
1283
1349
1284
if (targetType == null || valueType == null ) {
0 commit comments