]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7459) Fixed check for alread defined value name in the module. 02/902/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 1 Sep 2017 13:03:24 +0000 (16:03 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 1 Sep 2017 13:29:02 +0000 (16:29 +0300)
Change-Id: I2826c194a0210da4b63746caa7ea92e2e6e60d26

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.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/ClashingJavaImport.scl [new file with mode: 0644]
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ConstructorNameClash.scl

index ff5ee3b2902fa0384258f246776d534dbed0d617..ec32ea2981ec9cb68692a7126c4398049e986968 100644 (file)
@@ -712,7 +712,7 @@ public class Elaboration {
                     type);
             if(callJava != null) {
                 NameExistenceChecks.checkIfValueExists(errorLog, javaMethod.location,
-                        importedEnvironment, name);
+                        importedEnvironment, module, name);
                 SCLValue value = module.addValue(name, callJava);
                 value.definitionLocation = javaMethod.methodName.location;
                 if(isPrivate)
@@ -1137,7 +1137,7 @@ public class Elaboration {
                 value.setType(constructor.getType());
                 
                 NameExistenceChecks.checkIfValueExists(errorLog, constructor.loc,
-                        importedEnvironment, constructor.name.name);
+                        importedEnvironment, module, constructor.name.name);
                 if(module.addValue(value)) {
                     errorLog.log(constructor.loc,
                             "Value " + constructor.name.name + " is already defined.");
@@ -1152,7 +1152,7 @@ public class Elaboration {
                 SCLValue value = method.createValue();
                 value.definitionLocation = method.location;
                 NameExistenceChecks.checkIfValueExists(errorLog, Locations.NO_LOCATION,
-                        importedEnvironment, value.getName().name);
+                        importedEnvironment, module, value.getName().name);
 
                 if(module.addValue(value)) {
                     String name = method.getName();
@@ -1172,7 +1172,7 @@ public class Elaboration {
             
             long location = valueDefinitionsAst.getLocation(name);
             NameExistenceChecks.checkIfValueExists(errorLog, location,
-                    importedEnvironment, value.getName().name);
+                    importedEnvironment, module, value.getName().name);
             value.definitionLocation = location;
             if(module.addValue(value))
                 errorLog.log(location, "Value " + name + " is already defined.");
index d21e215f6ac0e156d4135e93ded5e58eeeb9539e..b9f2f8597a03f8a0cd74b2a74082ca363adb663b 100644 (file)
@@ -5,24 +5,30 @@ import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
 import org.simantics.scl.compiler.environment.AmbiguousNameException;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.errors.ErrorLog;
+import org.simantics.scl.compiler.module.ConcreteModule;
 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
 
 public class NameExistenceChecks {
     public static void checkIfValueExists(ErrorLog errorLog, long location,
-            Environment environment, String name) {
-        if(SCLCompilerConfiguration.ALLOW_OVERLOADING)
+            Environment environment, ConcreteModule currentModule, String name) {
+        if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
+            if(currentModule.getValue(name) != null) {
+                errorLog.log(location,
+                        "Value " + name + " has already been defined in this module.");
+            }
             return;
+        }
         else {
             try {
                 SCLValue value = environment.getLocalNamespace().getValue(name);
                 if(value != null)
                     errorLog.log(location,
-                            "Value " + name + " is already defined in the module " + 
+                            "Value " + name + " has already been defined in the module " + 
                                     value.getName().module + 
                             " that is imported to the default namespace.");
             } catch(AmbiguousNameException e) {
                 errorLog.log(location,
-                        "Value " + name + " is already defined in the modules " + 
+                        "Value " + name + " has already been defined in the modules " + 
                                 e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  
                         " that are imported to the default namespace.");
             }
@@ -35,12 +41,12 @@ public class NameExistenceChecks {
             TypeDescriptor tdesc = environment.getLocalNamespace().getTypeDescriptor(name);
             if(tdesc != null)
                 errorLog.log(location,
-                        "Type " + name + " is already defined in the module " + 
+                        "Type " + name + " has already been defined in the module " + 
                                 tdesc.name.module + 
                         " that is imported to the default namespace.");
         } catch(AmbiguousNameException e) {
             errorLog.log(location,
-                    "Type " + name + " is already defined in the modules " + 
+                    "Type " + name + " has already been defined in the modules " + 
                             e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  
                     " that are imported to the default namespace.");
         }
index cf3aa021b44981dddb463588e46b0bc5cfeb0b46..275bba86e8d1a945283b843ad9c4afdbc388bb26 100644 (file)
@@ -20,6 +20,7 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void ClashingClass() { test(); }
     @Test public void ClashingData() { test(); }
     @Test public void ClashingInstance() { test(); }
+    @Test public void ClashingJavaImport() { test(); }
     @Test public void ClashingValueType() { test(); }
     @Test public void ClosingBrace() { test(); }
     @Test public void CHR1() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ClashingJavaImport.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ClashingJavaImport.scl
new file mode 100644 (file)
index 0000000..7b8fc13
--- /dev/null
@@ -0,0 +1,7 @@
+importJava "java.lang.String" where
+    valueOf :: Integer -> String 
+    valueOf :: Double -> String
+    
+main = "Should not be executed."
+--
+3:5-3:32: Value valueOf has already been defined in this module.
\ No newline at end of file
index 6261943961d45efdfc09f532994827c74dfe4c31..babfb5a580e5fa0b9d758cbe1b441a0ec51ab5cc 100644 (file)
@@ -4,4 +4,5 @@ data Vec3 = Vec2 Double Double Double
 
 main = "Not to be executed."
 --
+3:13-3:38: Value Vec2 has already been defined in this module.
 3:13-3:38: Value Vec2 is already defined.
\ No newline at end of file