From: Tuukka Lehtonen Date: Thu, 13 Jun 2019 11:37:04 +0000 (+0000) Subject: Merge "Fix endless loop in type inference for over-applied functions" X-Git-Tag: v1.43.0~136^2~147 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=d85a4d990c5cac9d0c70781a265f02888b3aaa43;hp=78e89544a2077001fe3d1486f38a141cda7e10a8 Merge "Fix endless loop in type inference for over-applied functions" --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java index 7f50d730b..06ff05c18 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java @@ -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); 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 6a416687d..f577ad37d 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 @@ -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 index 000000000..9331fa30d --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/TypeInferenceBug4.scl @@ -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 Integer)> is not given and cannot be derived. +8:8-8:19: Application of non-function +8:16-8:17: Expected got Integer>.