From: Hannu Niemistö Date: Fri, 24 Nov 2017 11:51:11 +0000 (+0200) Subject: Fixed a bug related to as-pattern in list comprehension. X-Git-Tag: v1.31.0~14 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F1261%2F5;p=simantics%2Fplatform.git Fixed a bug related to as-pattern in list comprehension. refs #7642 Change-Id: I7f9b3b45d545e2fe793fcaa93b9d392972f0e53b --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java index 78f7ce115..10045b34f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java @@ -48,13 +48,19 @@ public class EListComprehension extends SimplifiableExpression { @Override public Expression simplify(SimplificationContext context) { + //System.out.println("--------"); context.pushLocation(location); try { - CompiledQualifier cq = qualifier.compile(context); + CompiledQualifier cq = qualifier.compile(context); + /* + System.out.println("cq.pattern = " + cq.pattern); + System.out.println("cq.value = " + cq.value); + System.out.println("head = " + head); + */ Expression exp = context.mapList( context.lambda(cq.pattern, head), cq.value); - //System.out.println("simplified: " + exp); + //System.out.println("simplified = " + exp); /*try { exp.validateType(context.getEnvironment()); } catch (TypeValidationException e) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java index 04f6791ac..0a380130f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java @@ -178,6 +178,13 @@ public class CollectFreeVariablesVisitor extends StandardExpressionVisitor { freeVariables.remove(variable); } + @Override + public void visit(EAsPattern expression) { + if(expression.var != null) + freeVariables.add(expression.var); + expression.pattern.accept(this); + } + public THashSet getFreeVariables() { return freeVariables; } diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java index 00af273c7..9e5d79216 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java @@ -136,6 +136,7 @@ public class ModuleRegressionTests extends TestBase { @Test public void LambdaMatch() { test(); } @Test public void Layout1() { test(); } @Test public void List() { test(); } + @Test public void ListComprehensionBug1() { test(); } @Test public void ListError1() { test(); } @Test public void ListError2() { test(); } @Test public void ListFunctions() { test(); } diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListComprehensionBug1.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListComprehensionBug1.scl new file mode 100644 index 000000000..86e9774c6 --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListComprehensionBug1.scl @@ -0,0 +1,8 @@ +import "Prelude" + +f :: [(String,String)] -> [(String,String,String)] +f l = [(show m,x,y) | m@(x,y) <-l ] + +main = f [] +-- +[]