]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NamespaceOfModule.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / NamespaceOfModule.java
index 7b2ee618f5dcf87d2becb248eb49c4e9b8ac6dda..8ade1602e23e730ba4e37227eb5ef09dd861eb7c 100644 (file)
@@ -1,7 +1,6 @@
 package org.simantics.scl.compiler.compilation;
 
-import gnu.trove.procedure.TObjectProcedure;
-
+import java.util.Arrays;
 import java.util.function.Consumer;
 
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
@@ -18,8 +17,11 @@ import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
 import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
 import org.simantics.scl.compiler.module.Module;
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
 import org.simantics.scl.compiler.types.TCon;
 
+import gnu.trove.procedure.TObjectProcedure;
+
 public class NamespaceOfModule implements Namespace {
     private final Namespace base;
     private final Module module;
@@ -37,9 +39,30 @@ public class NamespaceOfModule implements Namespace {
     @Override
     public SCLValue getValue(String name) throws AmbiguousNameException {
         SCLValue value = module.getValue(name);
+        if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
+            SCLValue value2;
+            try {
+                value2 = base.getValue(name);
+            } catch(AmbiguousNameException e) {
+                if(value != null) {
+                    String[] conflictingModules = Arrays.copyOf(e.conflictingModules, e.conflictingModules.length+1);
+                    conflictingModules[e.conflictingModules.length] = module.getName();
+                    throw new AmbiguousNameException(Arrays.asList(conflictingModules), e.name);
+                }
+                else
+                    throw e;
+            }
+            if(value == null)
+                return value2;
+            if(value2 == null)
+                return value;
+            throw new AmbiguousNameException(Arrays.asList(value.getName().module, value2.getName().module), value.getName().name);
+        }
+        else {
         if(value != null)
             return value;
         return base.getValue(name);
+        }
     }
 
     @Override