]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed a bug related to as-pattern in list comprehension. 61/1261/5
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 24 Nov 2017 11:51:11 +0000 (13:51 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 30 Nov 2017 15:31:50 +0000 (17:31 +0200)
refs #7642

Change-Id: I7f9b3b45d545e2fe793fcaa93b9d392972f0e53b

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListComprehensionBug1.scl [new file with mode: 0644]

index 78f7ce115c24b6b22eb06df747cb2ca7890df050..10045b34fb1e156e917874c44066041282f5f83f 100644 (file)
@@ -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) {
index 04f6791ac32b55aa238bfd109e7803a8f5b67b0e..0a380130f561080501f0ce5c33ae4942b2baaa86 100644 (file)
@@ -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<Variable> getFreeVariables() {
         return freeVariables;
     }
index 00af273c71d8c1295e70e61a9b0e13b9b4d6c09b..9e5d79216261816b76820ce148b35c550925cc74 100644 (file)
@@ -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 (file)
index 0000000..86e9774
--- /dev/null
@@ -0,0 +1,8 @@
+import "Prelude"
+
+f :: [(String,String)] -> [(String,String,String)] 
+f l = [(show m,x,y) | m@(x,y) <-l ]
+
+main = f []  
+--
+[]