diff --git a/lib/member_builder.js b/lib/member_builder.js index 53ba11b..f098258 100644 --- a/lib/member_builder.js +++ b/lib/member_builder.js @@ -77,6 +77,15 @@ exports.buildMethod = function( var prev_data = scanMembers( members, name, base ), prev = ( prev_data ) ? prev_data.member : null; + // do not permit private abstract methods (doesn't make sense, since + // they cannot be inherited/overridden) + if ( keywords[ 'abstract' ] && keywords[ 'private' ] ) + { + throw TypeError( + "Method '" + name + "' cannot be both private and abstract" + ); + } + // search for any previous instances of this member if ( prev ) { diff --git a/test/test-member_builder-method.js b/test/test-member_builder-method.js index 80721f9..e6f7775 100644 --- a/test/test-member_builder-method.js +++ b/test/test-member_builder-method.js @@ -276,3 +276,18 @@ mb_common.assertCommon(); ); } )(); + +/** + * It does not make sense to be able to declare abstract private methods, since + * they cannot be inherited and overridden by subtypes. + */ +( function testCannotDeclareAbstractPrivateMethods() +{ + mb_common.value = function() {}; + + assert.throws( function() + { + mb_common.buildMemberQuick( { 'private': true, 'abstract': true } ); + }, TypeError, "Cannot declare private abstract method" ); +} )(); +