diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index 5d29a29..91a072b 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -672,7 +672,7 @@ function validateAbstract( ctor, cname, abstract_methods, auto ) { if ( ctor.___$$abstract$$ ) { - if ( abstract_methods.__length === 0 ) + if ( !auto && ( abstract_methods.__length === 0 ) ) { throw TypeError( "Class " + ( cname || "(anonymous)" ) + " was declared as " + diff --git a/lib/Trait.js b/lib/Trait.js index 3aa9e6c..e1c18ff 100644 --- a/lib/Trait.js +++ b/lib/Trait.js @@ -90,11 +90,6 @@ Trait.extend = function( dfn ) // object will be used to define the hidden abstract class) var name = dfn.__name || '(Trait)'; - // we need at least one abstract member in order to declare a class as - // abstract (in this case, our trait class), so let's create a dummy one - // just in case DFN does not contain any abstract members itself - dfn[ 'abstract protected ___$$trait$$' ] = []; - // augment the parser to handle our own oddities dfn.___$$parser$$ = { each: _parseMember, @@ -102,6 +97,10 @@ Trait.extend = function( dfn ) getset: _parseGetSet, }; + // automatically mark ourselves as abstract if an abstract method is + // provided + dfn.___$$auto$abstract$$ = true; + // give the abstract trait class a distinctive name for debugging dfn.__name = '#AbstractTrait#'; @@ -289,8 +288,6 @@ function createConcrete( acls ) // a constructor that accepts the protected member object of the // containing class var dfn = { - 'protected ___$$trait$$': function() {}, - // protected member object (we define this as protected so that the // parent ACLS has access to it (!), which is not prohibited since // JS does not provide a strict typing mechanism...this is a kluge) @@ -506,7 +503,7 @@ function mixMethods( src, dest, vis, iname ) // TODO: this is a kluge; we'll use proper reflection eventually, // but for now, this is how we determine if this is an actual method // vs. something that just happens to be on the visibility object - if ( !( src[ f ].___$$keywords$$ ) || f === '___$$trait$$' ) + if ( !( src[ f ].___$$keywords$$ ) ) { continue; }