Added member collision unit test

parser.sync-conflict-20210405-185821-O3W7KWN
Tristan B. V. Kildaire 2021-04-01 21:08:37 +02:00
parent b97fdba551
commit 0e79bc77ed
3 changed files with 56 additions and 6 deletions

View File

@ -568,6 +568,50 @@ unittest
}
}
/* Test name colliding with member */
unittest
{
import std.file;
import std.stdio;
import compiler.lexer;
import compiler.parsing.core;
string sourceFile = "source/tlang/testing/collide_member.t";
File sourceFileFile;
sourceFileFile.open(sourceFile); /* TODO: Error handling with ANY file I/O */
ulong fileSize = sourceFileFile.size();
byte[] fileBytes;
fileBytes.length = fileSize;
fileBytes = sourceFileFile.rawRead(fileBytes);
sourceFileFile.close();
string sourceCode = cast(string) fileBytes;
Lexer currentLexer = new Lexer(sourceCode);
currentLexer.performLex();
Parser parser = new Parser(currentLexer.getTokens());
Module modulle = parser.parse();
TypeChecker typeChecker = new TypeChecker(modulle);
/* Setup testing variables */
Entity memberFirst = typeChecker.getResolver().resolveBest(typeChecker.getModule, "a.b");
try
{
/* Perform test */
typeChecker.beginCheck();
/* Shouldn't reach here, collision exception MUST occur */
assert(false);
}
catch (CollidingNameException e)
{
/* Make sure the member a.b.c.c collided with a.b.c container */
assert(e.attempted != memberFirst);
}
}
/* Test name colliding with container name (1/2) */
unittest

View File

@ -27,7 +27,7 @@ public final class CollidingNameException : TypeCheckerException
/**
* The colliding Entity
*/
private Entity attempted;
public Entity attempted;
/**
* The Container we are in

View File

@ -1,8 +1,14 @@
module x;
module y;
int y;
void y()
class a
{
class b
{
}
class b
{
}
}