Skip to content

Commit

Permalink
Fixes #155
Browse files Browse the repository at this point in the history
  • Loading branch information
iccir committed Sep 25, 2018
1 parent db5a56a commit 38254a1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,6 @@ warn-this-in-methods | Boolean | Warn about usage of 'this' in NilScript m
warn-self-in-non-methods | Boolean | Warn about usage of 'self' in non-NilScript methods
warn-unknown-ivars | Boolean | Warn about unknown ivars
warn-unknown-selectors | Boolean | Warn about usage of unknown selectors
warn-unknown-superclasses | Boolean | Warn about usage of unknown selectors
warn-unused-ivars | Boolean | Warn about unused ivars

Valid properties for each `file` or `defs` object:
Expand Down
1 change: 0 additions & 1 deletion src/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const sPublicOptions = [
"warn-self-in-non-methods", // Boolean, warn about usage of 'self' in non-methods
"warn-unknown-ivars", // Boolean, warn about unknown ivars
"warn-unknown-selectors", // Boolean, warn about usage of unknown selectors
"warn-unknown-superclasses", // Boolean, warn about usage of unknown superclasses
"warn-unused-ivars", // Boolean, warn about unused ivars

// Private / Development
Expand Down
4 changes: 2 additions & 2 deletions src/Errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ NSError.VariableAlreadyDeclared = "NilScriptVariableAlreadyDeclaredError"
NSError.VariableNotYetDeclared = "NilScriptVariableNotYetDeclaredError";
NSError.RestrictedUsage = "NilScriptRestrictedUsageError";
NSError.APIMisuse = "NilScriptAPIMisuseError";
NSError.CircularClassHierarchy = "NilScriptCircularClassHierarchyError";
NSError.UnknownSuperclass = "NilScriptUnknownSuperclassError";

const NSWarning = { };

NSWarning.CircularClassHierarchy = "NilScriptCircularClassHierarchyWarning";
NSWarning.UnknownSuperclass = "NilScriptUnknownSuperclassWarning";
NSWarning.UnknownSelector = "NilScriptUnknownSelectorWarning";
NSWarning.UseOfThisInMethod = "NilScriptUseOfThisInMethodWarning";
NSWarning.UseOfSelfInNonMethod = "NilScriptUseOfSelfInNonMethodWarning";
Expand Down
9 changes: 0 additions & 9 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ generate()
let optionWarnSelfInNonMethod = options["warn-self-in-non-methods"];
let optionWarnUnknownIvars = options["warn-unknown-ivars"];
let optionWarnUnknownSelectors = options["warn-unknown-selectors"];
let optionWarnUnknownSuperclasses = options["warn-unknown-superclasses"];
let optionWarnUnusedIvars = options["warn-unused-ivars"];
let optionStrictFunctions = options["strict-functions"];
let optionStrictObjectLiterals = options["strict-object-literals"];
Expand Down Expand Up @@ -524,14 +523,6 @@ generate()
if (superName) {
constructorCallSuper = getClassAsRuntimeVariable(superName) + ".call(this);";
superSelector = "{" + symbolTyper.getSymbolForClassName(superName) + ":1}";

if (optionWarnUnknownSuperclasses) {
let superclass = model.classes[superName];

if (!superclass || superclass.placeholder == true) {
warnings.push(Utils.makeError(NSWarning.UnknownSuperclass, "Use of unknown superclass '" + superName + "'.", node.superClass));
}
}
}

let constructorSetIvars = generateIvarAssignments(currentClass);
Expand Down
25 changes: 16 additions & 9 deletions src/model/NSClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ constructor(location, name, superclassName, protocolNames)

// Warnings during the prepare() phase
this.prepareWarnings = [ ];
this.superclass = null;

// All selectors the class responds to (inherited + synthesized). *not archived*
this._knownSelectors = null;
Expand Down Expand Up @@ -184,20 +185,24 @@ _doAutomaticSynthesis()
}


_checkForCircularHierarchy(model)
_checkHierarchy(model)
{
let visited = [ this.name ];
let superclass = this.superclassName ? model.classes[this.superclassName] : null;
let superclassName = this.superclassName;

if (superclassName && (!this.superclass || this.superclass.placeholder)) {
throw Utils.makeError(NSError.UnknownSuperclass, "Unknown superclass: '" + this.superclassName + "'", this.location);
}

while (superclass) {
if (visited.indexOf(superclass.name) >= 0) {
this.prepareWarnings.push(Utils.makeError(NSWarning.CircularClassHierarchy, "Circular class hierarchy detected: '" + visited.join(",") + "'", this.location));
break;
let currentSuperclass = this.superclass;
while (currentSuperclass) {
if (visited.indexOf(currentSuperclass.name) >= 0) {
throw Utils.makeError(NSError.CircularClassHierarchy, "Circular class hierarchy detected: '" + visited.join("', '") + "'");
}

visited.push(superclass.name);
visited.push(currentSuperclass.name);

superclass = model.classes[superclass.superclassName];
currentSuperclass = model.classes[currentSuperclass.superclassName];
}
}

Expand Down Expand Up @@ -237,8 +242,10 @@ prepare(model)

this.prepareWarnings = [ ];

this.superclass = this.superclassName ? model.classes[this.superclassName] : null;
this._checkHierarchy(model);

this._doAutomaticSynthesis();
this._checkForCircularHierarchy(model);

this._knownSelectors = { };

Expand Down
19 changes: 10 additions & 9 deletions test/multi/TestErrors.oj
Original file line number Diff line number Diff line change
Expand Up @@ -318,27 +318,29 @@ function test() {

// --------------------------------------------------------------------
// @name Circular Class 1
// @error-no-line NilScriptCircularClassHierarchyError

@class CircularClassA : CircularClassB //@warning NilScriptCircularClassHierarchyWarning
@class CircularClassA : CircularClassB
@end


@class CircularClassB : CircularClassA //@warning NilScriptCircularClassHierarchyWarning
@class CircularClassB : CircularClassA
@end

// --------------------------------------------------------------------
// @name Circular Class 2
// @error-no-line NilScriptCircularClassHierarchyError

@class CircularClassA : CircularClassB //@warning NilScriptCircularClassHierarchyWarning
@class CircularClassA : CircularClassB
@end

@class CircularClassB : CircularClassC //@warning NilScriptCircularClassHierarchyWarning
@class CircularClassB : CircularClassC
@end

@class CircularClassC : CircularClassD //@warning NilScriptCircularClassHierarchyWarning
@class CircularClassC : CircularClassD
@end

@class CircularClassD : CircularClassA //@warning NilScriptCircularClassHierarchyWarning
@class CircularClassD : CircularClassA
@end

// --------------------------------------------------------------------
Expand Down Expand Up @@ -456,10 +458,9 @@ var arr = [,,,,]; //@warning NilScriptUseOfEmptyArrayElementWarning


// --------------------------------------------------------------------
// @name Unknown Class
// @opts { "warn-unknown-superclasses": true }
// @name Unknown Super Class

@class Foo : NonExistantSuperClass //@warning NilScriptUnknownSuperclassWarning
@class Foo : NonExistantSuperClass //@error NilScriptUnknownSuperclassError

@end

Expand Down

0 comments on commit 38254a1

Please sign in to comment.