Concrete methods cannot be overridden by abstract methods
parent
37e5b1d94d
commit
c7b262b271
|
@ -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 )
|
||||||
|
|
|
@ -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" );
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue