diff --git a/src/org/rascalmpl/interpreter/matching/NegativePattern.java b/src/org/rascalmpl/interpreter/matching/NegativePattern.java index f5d9c791b05..40bf1d5a332 100644 --- a/src/org/rascalmpl/interpreter/matching/NegativePattern.java +++ b/src/org/rascalmpl/interpreter/matching/NegativePattern.java @@ -20,7 +20,10 @@ import org.rascalmpl.interpreter.IEvaluatorContext; import org.rascalmpl.interpreter.env.Environment; import org.rascalmpl.interpreter.result.Result; +import org.rascalmpl.values.IRascalValueFactory; + import io.usethesource.vallang.IValue; +import io.usethesource.vallang.INumber; import io.usethesource.vallang.type.Type; public class NegativePattern extends AbstractMatchingResult { @@ -43,7 +46,7 @@ public void initMatch(Result subject){ @Override public boolean mayMatch(Type subjectType, Environment env){ - return pat.mayMatch(subjectType, env); + return subjectType.isSubtypeOf(tf.numberType()) && pat.mayMatch(subjectType, env); } @Override @@ -53,6 +56,11 @@ public boolean hasNext() { @Override public boolean next() { - return pat.next(); + if (pat.next()) { + if (subject.getDynamicType().isNumber()) { + return ((INumber) subject.getValue()).lessEqual(IRascalValueFactory.getInstance().integer(0)).getValue(); + } + } + return false; } } diff --git a/src/org/rascalmpl/semantics/dynamic/Expression.java b/src/org/rascalmpl/semantics/dynamic/Expression.java index ba5f629189d..8aaae5daeb1 100644 --- a/src/org/rascalmpl/semantics/dynamic/Expression.java +++ b/src/org/rascalmpl/semantics/dynamic/Expression.java @@ -1918,8 +1918,15 @@ public IBooleanResult buildBacktracker(IEvaluatorContext __eval) { } @Override + @SuppressWarnings("unchecked") public IMatchingResult buildMatcher(IEvaluatorContext __eval, boolean bindTypeParameters) { - return new NegativePattern(__eval, this, getArgument().buildMatcher(__eval, bindTypeParameters)); + Type t = getArgument().typeOf(__eval.getCurrentEnvt(), (IEvaluator>) __eval, bindTypeParameters); + + if (getArgument().isTypedVariable() || getArgument().isQualifiedName() || getArgument().isLiteral()) { + return new NegativePattern(__eval, this, getArgument().buildMatcher(__eval, bindTypeParameters)); + } + + throw new UnexpectedType(TF.numberType(), t, getLocation()); } @Override