Skip to content
Snippets Groups Projects
Commit 4c97fc19 authored by Zbynek Slajchrt's avatar Zbynek Slajchrt
Browse files

A bug in the cast analyser fixed

parent 5631b210
Branches
No related tags found
No related merge requests found
...@@ -324,9 +324,14 @@ public class CastUtils { ...@@ -324,9 +324,14 @@ public class CastUtils {
} else { } else {
Casts positiveCasts = new Casts(cs.stream().filter(c -> existsConvertibleActualType(actualInputTypes, c.inputType(), true)).collect(Collectors.toList())); 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); TypeExpr positive = positiveCasts.casts().stream().map(c -> TypeExpr.atom(c.resultType())).reduce((res, te) -> res.or(te)).orElse(TypeExpr.NOTHING);
Casts negativeCasts = new Casts(
Casts negativeCasts = new Casts(cs.stream().filter(c -> !positiveCasts.resultTypes().contains(c.resultType()) && cs.stream().filter(c -> !existsConvertibleActualType(actualInputTypes, c.inputType(), true) &&
!existsConvertibleActualType(actualInputTypes, c.inputType(), true)).collect(Collectors.toList())); // 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); 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); return positive.and(negative);
......
...@@ -127,8 +127,7 @@ public class ResultTypesAnalyserTest { ...@@ -127,8 +127,7 @@ public class ResultTypesAnalyserTest {
@Test @Test
public void testAsLogicalVector() { public void testAsLogicalVector() {
arg.asLogicalVector(); arg.asLogicalVector();
assertTypes(RNull.class, RMissing.class, byte.class, RLogicalVector.class, assertTypes(RNull.class, RMissing.class, byte.class, RLogicalVector.class);
RArgsValuesAndNames.class);
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment