From e7905aace2527cb3c9d21b3650e1fa8db93d14bd Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 30 Mar 2021 21:29:57 +0200 Subject: [PATCH] Made class name constraints good. You can have your duplicate names nested but not at same level --- source/tlang/compiler/typecheck/core.d | 30 ++++++++++++++++++++++++++ source/tlang/testing/basic1.t | 27 +++++++++++++---------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 34364b8..06d0a69 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -313,6 +313,36 @@ public final class TypeChecker } else { + /* Get the current container's parent container */ + Container parentContainer = c.parentOf(); + + /* If c (container is Module) then it has no Parent */ + if(!parentContainer) + { + if(cmp(c.getName(), clazz.getName()) == 0) + { + Parser.expect("Cannot use name of module, in use"); + } + } + + /* Find the name starting in upper cotainer */ + Entity clazzAbove = resolveUp(parentContainer, clazz.getName()); + + if(!clazzAbove) + { + + } + else + { + Parser.expect("Name in use abpve us, bad"~to!(string)(clazz)); + } + + /* If the Container's parent container is Module then we can have + /* TODO: Check that it doesn;t equal any class up the chain */ + /* TODO: Exclude Module from this */ + + + // /* Still check if there is something with our name above us */ // Container parentContainer = c.parentOf(); diff --git a/source/tlang/testing/basic1.t b/source/tlang/testing/basic1.t index 428f8df..7789900 100644 --- a/source/tlang/testing/basic1.t +++ b/source/tlang/testing/basic1.t @@ -21,16 +21,16 @@ public ubyte k = 1; private ubyte k2 = 1; protected ubyte k3 = -1; -class ooga : P +class ooga : O { } -class P : ooga +class O : ooga { - class P + class I { - class P : ooga + class L : ooga { } @@ -45,20 +45,25 @@ public class clazz1 int k; print("Hello world"); - public class clazz1 + public class clazz3 { - class clazz1 + class bruh2 { } } } +class myModule +{ + +} + class bruh { - class L + class bruh1 { - class bruh + class bruh2 { } @@ -67,15 +72,15 @@ class bruh class clazz2 : bruh { - class clazz2 + class clazzU { } - class clazz1 + class clazz12 { int j; - private class clazz_2_2_1 : bruh, bruh2 + private class clazz_2_2_1 : bruh, clazzU { }