1
0
Fork 0

Concrete methods cannot be overridden by abstract methods

closure/master
Mike Gerwitz 2011-01-24 23:52:06 -05:00
parent 37e5b1d94d
commit c7b262b271
2 changed files with 26 additions and 0 deletions

View File

@ -76,6 +76,15 @@ exports.buildMethod = function( members, meta, name, value, keywords )
); );
} }
// do not allow overriding concrete methods with abstract
if ( keywords[ 'abstract' ] && !( util.isAbstractMethod( prev ) ) )
{
throw TypeError(
"Cannot override concrete method '" + name + "' with " +
"abstract method"
);
}
// ensure parameter list is at least the length of its supertype // ensure parameter list is at least the length of its supertype
if ( ( value.__length || value.length ) if ( ( value.__length || value.length )
< ( prev.__length || prev.length ) < ( prev.__length || prev.length )

View File

@ -134,3 +134,20 @@ mb_common.assertCommon();
mb_common.members[ 'public' ][ mb_common.name ](); mb_common.members[ 'public' ][ mb_common.name ]();
} )(); } )();
/**
* Once a concrete implementation has been defined for a method, a subtype
* cannot make it abstract.
*/
( function testCannotOverrideConcreteMethodWithAbstractMethod()
{
// concrete method
mb_common.value = function() {};
mb_common.buildMemberQuick();
assert.throws( function()
{
mb_common.buildMemberQuick( { 'abstract': true }, true );
}, TypeError, "Cannot override concrete method with abstract method" );
} )();