Fix endless loop in type inference for over-applied functions 42/2942/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Tue, 11 Jun 2019 13:57:07 +0000 (16:57 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Tue, 11 Jun 2019 13:57:07 +0000 (16:57 +0300)
gitlab #303

Change-Id: I5b7c4bc9dafc2cabcc5b152525824d7bc3432345

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

index 7f50d73..06ff05c 100644 (file)
@@ -249,6 +249,12 @@ public class EApply extends Expression {
             current.setType(mfun.returnType);
 
             if(marity < current.parameters.length) {
+                if (marity == 0) {
+                    // Cannot eat away any more parameters
+                    context.getErrorLog().log(location, "Application of non-function");
+                    return current;
+                }
+                
                 Expression[] missingParameters = Arrays.copyOfRange(current.parameters, marity, current.parameters.length);
                 functionType = mfun.returnType;
                 current.parameters = Arrays.copyOf(current.parameters, marity);
index 6a41668..f577ad3 100644 (file)
@@ -291,6 +291,7 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void TypeClassBug1() { test(); }
     @Test(timeout=1000L) public void TypeInferenceBug2() { test(); }
     @Test public void TypeInferenceBug3() { test(); }
+    @Test(timeout=100L) public void TypeInferenceBug4() { test(); }
     @Test public void TypeOf1() { test(); }
     @Test public void TypingBug1() { test(); }
     @Test public void TypingError1() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/TypeInferenceBug4.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/TypeInferenceBug4.scl
new file mode 100644 (file)
index 0000000..9331fa3
--- /dev/null
@@ -0,0 +1,14 @@
+import "Prelude"
+
+// See gitlab #303
+
+test :: () -> Integer
+test _ = let
+    f = id :: Integer -> Integer
+    in min f 1 f 2
+    
+main = test ()
+--
+8:8-8:11: Constraint <Ord (Integer -> Integer)> is not given and cannot be derived.
+8:8-8:19: Application of non-function
+8:16-8:17: Expected <Integer> got <Integer -> Integer>.