From 4c97fc1924863ccfafb66bcd83427126def4101f Mon Sep 17 00:00:00 2001 From: Zbynek Slajchrt <zbynek.slajchrt@oracle.com> Date: Wed, 28 Jun 2017 19:15:53 +0200 Subject: [PATCH] A bug in the cast analyser fixed --- .../com/oracle/truffle/r/nodes/casts/CastUtils.java | 11 ++++++++--- .../r/nodes/castsTests/ResultTypesAnalyserTest.java | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/CastUtils.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/CastUtils.java index 0b68e310c4..5480da712a 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/CastUtils.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/CastUtils.java @@ -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); diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/castsTests/ResultTypesAnalyserTest.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/castsTests/ResultTypesAnalyserTest.java index 3cfa577f86..19dea4141a 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/castsTests/ResultTypesAnalyserTest.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/castsTests/ResultTypesAnalyserTest.java @@ -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 -- GitLab