Overridden methods must have >= length parameter lists
parent
b8a6aa2af6
commit
e03d5861bb
|
@ -73,6 +73,15 @@ exports.buildMethod = function( members, meta, name, value, keywords )
|
|||
);
|
||||
}
|
||||
|
||||
// ensure parameter list is at least the length of its supertype
|
||||
if ( prev && (value.length < prev.length ) )
|
||||
{
|
||||
throw new TypeError(
|
||||
"Declaration of method '" + name + "' must be compatiable " +
|
||||
"with that of its supertype"
|
||||
);
|
||||
}
|
||||
|
||||
getMemberVisibility( members, keywords )[ name ] = value;
|
||||
};
|
||||
|
||||
|
|
|
@ -61,3 +61,31 @@ mb_common.assertCommon();
|
|||
}, TypeError, "Cannot override property with method" );
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* To ensure interfaces of subtypes remain compatible with that of their
|
||||
* supertypes, the parameter lists must match and build upon each other.
|
||||
*/
|
||||
( function testMethodOverridesMustHaveEqualOrGreaterParameters()
|
||||
{
|
||||
mb_common.value = function( one, two ) {};
|
||||
mb_common.buildMemberQuick();
|
||||
|
||||
assert.doesNotThrow( function()
|
||||
{
|
||||
mb_common.buildMemberQuick( {}, true );
|
||||
}, TypeError, "Method can have equal number of parameters" );
|
||||
|
||||
assert.doesNotThrow( function()
|
||||
{
|
||||
mb_common.value = function( one, two, three ) {};
|
||||
mb_common.buildMemberQuick( {}, true );
|
||||
}, TypeError, "Method can have greater number of parameters" );
|
||||
|
||||
assert.throws( function()
|
||||
{
|
||||
mb_common.value = function( one ) {};
|
||||
mb_common.buildMemberQuick( {}, true );
|
||||
}, TypeError, "Method cannot have lesser number of parameters" );
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue