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)
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.");
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();
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.");
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.");
}
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.");
}
@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(); }
--- /dev/null
+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
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