Skip to content
Snippets Groups Projects
Commit 2b2e61de authored by Zbyněk Šlajchrt's avatar Zbyněk Šlajchrt
Browse files

[GR-2798] A bug in the cast analyser fixed.

parents be52aef8 4c97fc19
No related branches found
No related tags found
No related merge requests found
......@@ -324,9 +324,14 @@ public class CastUtils {
} else {
Casts positiveCasts = new Casts(cs.stream().filter(c -> existsConvertibleActualType(actualInputTypes, c.inputType(), true)).collect(Collectors.toList()));
TypeExpr positive = positiveCasts.casts().stream().map(c -> TypeExpr.atom(c.resultType())).reduce((res, te) -> res.or(te)).orElse(TypeExpr.NOTHING);
Casts negativeCasts = new Casts(cs.stream().filter(c -> !positiveCasts.resultTypes().contains(c.resultType()) &&
!existsConvertibleActualType(actualInputTypes, c.inputType(), true)).collect(Collectors.toList()));
Casts negativeCasts = new Casts(
cs.stream().filter(c -> !existsConvertibleActualType(actualInputTypes, c.inputType(), true) &&
// Make sure that the negativeCasts set contains no
// cast whose return type is
// convertible to the return type of any cast from
// the positiveCasts set
positiveCasts.resultTypes().stream().allMatch(posResTp -> isConvertible(c.resultType(), posResTp, false) == Cast.Coverage.none)).collect(
Collectors.toList()));
TypeExpr negative = negativeCasts.casts().stream().map(c -> TypeExpr.atom(c.resultType()).not()).reduce((res, te) -> res.and(te)).orElse(TypeExpr.ANYTHING);
return positive.and(negative);
......
......@@ -127,8 +127,7 @@ public class ResultTypesAnalyserTest {
@Test
public void testAsLogicalVector() {
arg.asLogicalVector();
assertTypes(RNull.class, RMissing.class, byte.class, RLogicalVector.class,
RArgsValuesAndNames.class);
assertTypes(RNull.class, RMissing.class, byte.class, RLogicalVector.class);
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment