diff --git a/src/builder.js b/src/builder.js index 072fff3..30cb39b 100644 --- a/src/builder.js +++ b/src/builder.js @@ -342,6 +342,7 @@ build() } e.addValue(declaration.id.name, currentValue); + model.registerDeclaration(declaration.id.name, declaration); declaration.enumValue = currentValue; diff --git a/src/compiler.js b/src/compiler.js index f840c2d..4d8dce2 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -269,7 +269,7 @@ _runOnCompileCallback(onCompileCallback, ojFile, doneCallback) }, getContents: () => { - return lines.join("\n"); + return lines ? lines.join("\n") : "" }, getPath: () => { diff --git a/src/model/OJModel.js b/src/model/OJModel.js index ecfb626..0ae8a6a 100644 --- a/src/model/OJModel.js +++ b/src/model/OJModel.js @@ -383,12 +383,13 @@ getAggregateClass() return result; } -_registerDeclaration(name) + +registerDeclaration(name, node) { let existing = this._declarationMap[name]; if (existing) { - Utils.throwError(OJError.DuplicateDeclaration, "Duplicate declaration of '" + name + "'.") + Utils.throwError(OJError.DuplicateDeclaration, "Duplicate declaration of '" + name + "'.", node) } this._declarationMap[name] = true; @@ -400,7 +401,7 @@ addConst(ojConst) let name = ojConst.name; this.consts[name] = ojConst; - this._registerDeclaration(name); + this.registerDeclaration(name); } @@ -421,7 +422,8 @@ addEnum(ojEnum) } this.enums[name] = ojEnum; - this._registerDeclaration(name); + + this.registerDeclaration(name); } @@ -448,7 +450,7 @@ addClass(ojClass) } else { this.classes[name] = ojClass; - this._registerDeclaration(name); + this.registerDeclaration(name); } } @@ -474,7 +476,7 @@ addType(ojType) } this.types[name] = ojType; - this._registerDeclaration(name); + this.registerDeclaration(name); } @@ -483,7 +485,7 @@ addGlobal(ojGlobal) let name = ojGlobal.name; this.globals[name] = ojGlobal; - this._registerDeclaration(name); + this.registerDeclaration(name); } diff --git a/src/typechecker/Typechecker.js b/src/typechecker/Typechecker.js index c49ad5b..e470f80 100644 --- a/src/typechecker/Typechecker.js +++ b/src/typechecker/Typechecker.js @@ -108,6 +108,7 @@ check(model, defs, files, callback) let defsKey = ojFile.path + path.sep + defsSuffix; sourceFileMap[defsKey] = this._getSourceFile(defsKey, ojFile.contents); + originalFileMap[defsKey] = ojFile.path; }); if (!this._globalDefsSourceFile) { diff --git a/test/issues/TestIssue112.oj b/test/issues/TestIssue112.oj index f413e1c..6332dfc 100644 --- a/test/issues/TestIssue112.oj +++ b/test/issues/TestIssue112.oj @@ -15,7 +15,7 @@ function runTests() { - return [Foo runTest] == 5 + return [TestIssue112 runTest] == 5 } runTests(); diff --git a/test/multi/TestErrors.oj b/test/multi/TestErrors.oj index 9070ec7..3d94de7 100644 --- a/test/multi/TestErrors.oj +++ b/test/multi/TestErrors.oj @@ -290,13 +290,31 @@ function test() { @end - // -------------------------------------------------------------------- -// @name Duplicate Enum +// @name Duplicate Enum Name @enum Foo { Foo1, Foo2 } @enum Foo { Bar1, Bar2 } //@error OJDuplicateDeclarationError + +// -------------------------------------------------------------------- +// @name Duplicate Enum Value 1 + +@enum Foo { Foo1, Foo2 } +@enum Bar { Foo1, Foo2 } //@error OJDuplicateDeclarationError + + +// -------------------------------------------------------------------- +// @name Duplicate Enum Value 2 + +@enum { Foo1, FooDuplicate } + +@enum { + Foo2, + FooDuplicate //@error OJDuplicateDeclarationError +} + + // -------------------------------------------------------------------- // @name Circular Class 1 // @error-no-line OJCircularClassHierarchyError