mirror of
https://github.com/irmen/prog8.git
synced 2025-02-18 05:30:34 +00:00
+/* non-unique module names: provide more info, add TODO
This commit is contained in:
parent
fa5ecd6495
commit
d3e026d82a
@ -58,8 +58,24 @@ internal fun Program.checkIdentifiers(errors: IErrorReporter, options: Compilati
|
|||||||
lit2decl.applyModifications()
|
lit2decl.applyModifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modules.map { it.name }.toSet().size != modules.size) {
|
// Check if each module has a unique name.
|
||||||
throw FatalAstException("modules should all be unique")
|
// If not report those that haven't.
|
||||||
|
// TODO: move check for unique module names to earlier stage and/or to unit tests
|
||||||
|
val namesToModules = mapOf<String, MutableList<prog8.ast.Module>>().toMutableMap()
|
||||||
|
for (m in modules) {
|
||||||
|
var others = namesToModules[m.name]
|
||||||
|
if (others == null) {
|
||||||
|
namesToModules.put(m.name, listOf(m).toMutableList())
|
||||||
|
} else {
|
||||||
|
others.add(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val nonUniqueNames = namesToModules.keys
|
||||||
|
.map { Pair(it, namesToModules[it]!!.size) }
|
||||||
|
.filter { it.second > 1 }
|
||||||
|
.map { "\"${it.first}\" (x${it.second})"}
|
||||||
|
if (nonUniqueNames.size > 0) {
|
||||||
|
throw FatalAstException("modules must have unique names; of the ttl ${modules.size} these have not: $nonUniqueNames")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user