From fa65538fcc09cdf6e0db94cc4f88acade5b28b77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Fri, 29 Dec 2017 10:49:21 +0200 Subject: [PATCH] Fixed a bug related to the extent of variable frames (see test case) refs #7698 Change-Id: I18879f6cffb9f796f673f697711249c962b1e073 --- .../contexts/TranslationContext.java | 2 +- .../elaboration/expressions/EConstant.java | 5 +++++ .../elaboration/expressions/ELiteral.java | 4 ++++ .../compiler/tests/ModuleRegressionTests.java | 1 + .../scl/RepeatedVariableDefinitionBug.scl | 18 ++++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/RepeatedVariableDefinitionBug.scl diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java index 0e7df755c..535cc8c8b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java @@ -119,7 +119,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro public static boolean isConstructorName(String name) { int p = name.lastIndexOf('.'); char firstChar = name.charAt(p<0 ? 0 : p+1); - return Character.isUpperCase(firstChar); + return Character.isUpperCase(firstChar) || firstChar == '('; } /* Tries to resolve name as a local variable. It is assumed diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java index b33ebcf25..eb3f5ca4a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java @@ -261,4 +261,9 @@ public class EConstant extends Expression { EConstant other = (EConstant)expression; return value == other.value && Types.equals(typeParameters, other.typeParameters); } + + @Override + public boolean isConstructorApplication() { + return true; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java index bef28f20f..f82ae5101 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java @@ -119,4 +119,8 @@ public class ELiteral extends Expression { return value.equals(other.value); } + @Override + public boolean isConstructorApplication() { + return true; + } } 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 9e5d79216..e11755fc3 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 @@ -228,6 +228,7 @@ public class ModuleRegressionTests extends TestBase { @Test public void RedBlackTrees() { test(); } @Test public void Relations1() { test(); } @Test public void Relations2() { test(); } + @Test public void RepeatedVariableDefinitionBug() { test(); } @Test public void RepeatedVariableInPattern() { test(); } @Test public void Scanl() { test(); } @Test public void Search() { test(); } diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/RepeatedVariableDefinitionBug.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/RepeatedVariableDefinitionBug.scl new file mode 100644 index 000000000..e5ae38918 --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/RepeatedVariableDefinitionBug.scl @@ -0,0 +1,18 @@ +import "Prelude" + +test1 :: () +test1 = do + (problem, foo) = (1, 2) + problem = 1 + (problem, bar) = (3, 4) + () + +test2 :: () +test2 = do + (problem, foo) = (1, 2) + (problem, bar) = (3, 4) + () + +main = () +-- +() \ No newline at end of file -- 2.47.1