1
0
Fork 0

Implemented GH#3 Abstract keyword cannot be used with private members

closure/master
Mike Gerwitz 2011-03-29 23:39:49 -04:00
parent b8e512c69e
commit 8a3010c964
2 changed files with 24 additions and 0 deletions

View File

@ -77,6 +77,15 @@ exports.buildMethod = function(
var prev_data = scanMembers( members, name, base ), var prev_data = scanMembers( members, name, base ),
prev = ( prev_data ) ? prev_data.member : null; 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 // search for any previous instances of this member
if ( prev ) if ( prev )
{ {

View File

@ -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" );
} )();