This commit is contained in:
Tristan B. Velloza Kildaire 2021-04-01 14:38:11 +02:00
parent 21cef84983
commit 8a32272660
2 changed files with 27 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import compiler.parsing.core;
import compiler.symbols.check; import compiler.symbols.check;
import compiler.symbols.data; import compiler.symbols.data;
import compiler.typecheck.core; import compiler.typecheck.core;
import compiler.typecheck.exceptions;
void beginCompilation(string[] sourceFiles) void beginCompilation(string[] sourceFiles)
{ {
@ -47,7 +48,19 @@ void beginCompilation(string[] sourceFiles)
Module modulle = parser.parse(); Module modulle = parser.parse();
gprintln("Type checking and symbol resolution..."); gprintln("Type checking and symbol resolution...");
TypeChecker typeChecker = new TypeChecker(modulle); // try
// {
TypeChecker typeChecker = new TypeChecker(modulle);
// }
// catch(CollidingNameException e)
// {
// }
// catch(TypeCheckerException e)
// {
// }
// typeChecker.check(); // typeChecker.check();
} }
} }

View File

@ -2,6 +2,7 @@ module compiler.typecheck.exceptions;
import compiler.typecheck.core; import compiler.typecheck.core;
import compiler.symbols.data; import compiler.symbols.data;
import compiler.typecheck.resolution;
public class TypeCheckerException : Exception public class TypeCheckerException : Exception
{ {
@ -36,6 +37,18 @@ public final class CollidingNameException : TypeCheckerException
/* TODO: Set `msg` */ /* TODO: Set `msg` */
/* TODO: (Gogga it) Generate the error message */ /* TODO: (Gogga it) Generate the error message */
if(isCollidingWithContainer())
{
string containerPath = typeChecker.getResolver().generateName(modulle, defined);
string entityPath = typeChecker.getResolver().generateName(modulle, attempted);
msg = "Cannot have entity \""~entityPath~"\" with same name as container \""~containerPath~"\"";
}
else
{
string preExistingEntity = resolver.generateName(modulle, findPrecedence(c, entity.getName()));
string entityPath = resolver.generateName(modulle, entity);
msg = "Cannot have entity \""~entityPath~"\" with same name as entity \""~preExistingEntity~"\" within same container";
}
} }
public bool isCollidingWithContainer() public bool isCollidingWithContainer()