]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7508) Added missing effects in the simplification of EBind 76/1076/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 4 Oct 2017 19:24:31 +0000 (22:24 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 4 Oct 2017 19:24:31 +0000 (22:24 +0300)
Change-Id: I648db6332ebc7d6501dd07c44271bab0b5ab7857

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.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/MonadSyntax4.scl [new file with mode: 0644]

index c72776b35829ea91b6aa90037b4920bf35c39458..5664db7bfdd768f17dbbda87c45a5c6abb8ae995 100644 (file)
@@ -89,10 +89,6 @@ public class EBind extends SimplifiableExpression {
      */
     @Override
     public Expression simplify(SimplificationContext context) {    
-        value = value.simplify(context);
-        in = in.simplify(context);
-        pattern = pattern.simplify(context);
-        
         long loc = getLocation();
         monadType = Types.canonical(monadType);
         valueContentType = Types.canonical(valueContentType);
@@ -101,11 +97,11 @@ public class EBind extends SimplifiableExpression {
         Type[] types = blockType == BlockType.MonadE 
                 ? new Type[] {monadType, valueContentType, effect, inContentType} 
                 : new Type[] {monadType, valueContentType, inContentType};
-        Expression simplified = new EApply(loc,
+        Expression simplified = new EApply(loc, effect,
                 new EConstant(loc, context.getValue(blockType == BlockType.MonadE ? Names.Prelude_bindE : Names.Prelude_bind), types),
                 monadEvidence, 
                 value,
-                new ELambda(loc, new Case[] {
+                new ELambda(loc, effect, new Case[] {
                     new Case(new Expression[] { pattern }, in)
                 }));
         simplified.setType(getType());
index ccf86bbf5110204bcdf63bedf130dbc4e5327265..b01b771894a831b16d193d208317b746eede221e 100644 (file)
@@ -29,6 +29,12 @@ public class ELambda extends SimplifiableExpression {
         this.cases = cases;
     }
     
+    public ELambda(long loc, Type effect, Case ... cases) {
+        super(loc);
+        this.cases = cases;
+        this.effect = effect;
+    }
+    
     public ELambda(long loc, Expression pat, Expression exp) {
         this(loc, new Case(new Expression[] {pat}, exp));
     }
index 7e419f6abb2e4d25d526913a17a5b54f62b3d63a..91ddbc5e9742e8ac951340e6cb7df8ab96500985 100644 (file)
@@ -181,7 +181,8 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void MonadBug1() { test(); }
     @Test public void Monads1() { test(); }
     @Test public void MonadSyntax1() { test(); }    
-    @Test public void MonadSyntax3() { test(); }
+    @Test public void MonadSyntax3() { test(); }    
+    @Test public void MonadSyntax4() { test(); }
     @Test public void NoDefinitionErrorMessage() { test(); }
     @Test public void NoInstance() { test(); }
     @Test public void NoInstance2() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax4.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax4.scl
new file mode 100644 (file)
index 0000000..c410c98
--- /dev/null
@@ -0,0 +1,9 @@
+import "Prelude"
+
+main = ignore edo 
+  x <- [print "Hello"]
+  return (print "world!")
+--
+Hello
+world!
+()
\ No newline at end of file