From: Hannu Niemistö Date: Fri, 1 Sep 2017 13:03:24 +0000 (+0300) Subject: (refs #7459) Fixed check for alread defined value name in the module. X-Git-Tag: v1.31.0~210 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F02%2F902%2F2;p=simantics%2Fplatform.git (refs #7459) Fixed check for alread defined value name in the module. Change-Id: I2826c194a0210da4b63746caa7ea92e2e6e60d26 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index ff5ee3b29..ec32ea298 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -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."); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java index d21e215f6..b9f2f8597 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java @@ -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."); } 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 cf3aa021b..275bba86e 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 @@ -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 index 000000000..7b8fc1302 --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ClashingJavaImport.scl @@ -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 diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ConstructorNameClash.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ConstructorNameClash.scl index 626194396..babfb5a58 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ConstructorNameClash.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ConstructorNameClash.scl @@ -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