From: Tuukka Lehtonen Date: Thu, 13 Jun 2019 11:44:44 +0000 (+0000) Subject: Merge "Define ConnectionRelationType to make searching of instances possible" X-Git-Tag: v1.43.0~136^2~146 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=ae3bfd23d4b7c6bd581ad1238e25bd4f513b2643;hp=50f197d8b0f5824e930c5829db3f808cb6d455f4 Merge "Define ConnectionRelationType to make searching of instances possible" --- diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java index 8c052561e..0ca3b1b04 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java @@ -13,6 +13,8 @@ package org.simantics.modeling.ui.diagramEditor; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import org.eclipse.ui.PlatformUI; import org.simantics.Simantics; @@ -103,16 +105,21 @@ public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorA Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, r); if(diagram != null) return diagram; - if(selectedObjects.size() == 1) { - Object o = selectedObjects.iterator().next(); - if(o instanceof Resource) { - Resource res = (Resource)o; - if(graph.isInstanceOf(res, DIA.Element)) { - return graph.getPossibleObject(res, L0.PartOf); - } - } + // TODO: what if the selected objects are from different diagrams? + if (selectedObjects.size() > 0) { + Set diagrams = new HashSet<>(); + for (Object o : selectedObjects) { + if (o instanceof Resource) { + Resource res = (Resource)o; + if (graph.isInstanceOf(res, DIA.Element)) { + diagrams.add(graph.getPossibleObject(res, L0.PartOf)); + } + } + } + if (diagrams.size() == 1) { + return diagrams.iterator().next(); + } } - return null; } 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>.