Skip to content

Commit

Permalink
fix collect type calculator to correctly handle all collection types
Browse files Browse the repository at this point in the history
  • Loading branch information
pkourouklidis committed Jan 14, 2025
1 parent 2167176 commit 4ff8409
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ public class CollectTypeCalculator implements ITypeCalculator {
@Override
public EolType calculateType(EolType contextType, EolType iteratorType, EolType expressionType) {
String collectionName = ((EolCollectionType)contextType).getName();
return new EolCollectionType(collectionName, expressionType);
String newCollectionName = null;
if (collectionName.equals("Bag") || collectionName.equals("Set")) {
newCollectionName = "Bag";
}
else if (collectionName.equals("Sequence") || collectionName.equals("OrderedSet")){
newCollectionName = "Sequence";
}
else {
throw new RuntimeException("Unknown collection name");
}
return new EolCollectionType(newCollectionName, expressionType);
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
var seq : Sequence<Integer> = Sequence{0..9};
/*Sequence<Integer>*/seq.collect(e:Integer|e+1);
/*Bag<Integer>*/Bag{0..9}.collect(e:Integer|e+1);
/*Sequence<Integer>*/Sequence{0..9}.collect(e:Integer|e+1);
/*Bag<Integer>*/Set{0..9}.collect(e:Integer|e+1);
/*Sequence<Integer>*/OrderedSet{0..9}.collect(e:Integer|e+1);

0 comments on commit 4ff8409

Please sign in to comment.