Skip to content

Commit

Permalink
get us to where we at least only get errors for redefined constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmett authored and kustosz committed Jun 16, 2022
1 parent ba952e5 commit 0545f7a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.enso.interpreter.runtime.error;

import com.oracle.truffle.api.exception.AbstractTruffleException;
import org.enso.interpreter.runtime.Module;

/** An exception thrown when the program tries to redefine an already-defined constructor */
public class RedefinedConstructorException extends AbstractTruffleException {

/**
* Creates a new error.
*
* @param atom the method of the atom on which {@code method} is being defined
*/
public RedefinedConstructorException(String atom, Module scope) {
super("Constructors cannot be overloaded, but you have tried to overload " + atom + " in scope " + scope.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.enso.interpreter.runtime.Module;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.error.RedefinedConstructorException;
import org.enso.interpreter.runtime.error.RedefinedMethodException;
import org.enso.interpreter.runtime.error.RedefinedConversionException;

Expand Down Expand Up @@ -38,9 +39,17 @@ public ModuleScope(Module module) {
* @param constructor the constructor to register
*/
public void registerConstructor(AtomConstructor constructor) {
var name = constructor.getName();
if (constructors.containsKey(name))
throw new RedefinedConstructorException(name, module);
constructors.put(name, constructor);
}

public void forciblyRegisterConstructor(AtomConstructor constructor) {
constructors.put(constructor.getName(), constructor);
}


/** @return the associated type of this module. */
public AtomConstructor getAssociatedType() {
return associatedType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class RuntimeStubsGenerator(builtins: Builtins) {
BindingAnalysis,
"Non-parsed module used in stubs generator"
)
val constructors = localBindings.constructors.map { tp =>
val constructors = localBindings.constructors./*distinctBy(_.name). */map { tp =>
if (tp.builtinType) {
val builtinType = builtins.getBuiltinType(tp.name)
if (builtinType == null) {
throw new CompilerError("Unknown @BuiltinType " + tp.name)
}
scope.registerConstructor(builtinType)
scope.forciblyRegisterConstructor(builtinType)
builtinType.setShadowDefinitions(scope)
(tp, builtinType)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
}
}

/** Resolve a name to either an explicit sum type or a simple TypeArg. Used to link
* suggestions to concrete types, so the editor can know a fully qualified
* type name if possible.
*
* @param resolvedName the name to resolve
* @return how to present it to the suggestion engine
*/
private def buildResolvedUnionTypeName(
resolvedName: BindingsMap.ResolvedName
): Option[TypeArg] = resolvedName match {
Expand Down

0 comments on commit 0545f7a

Please sign in to comment.