1
0
Fork 0

Overridden methods must have >= length parameter lists

closure/master
Mike Gerwitz 2011-01-21 22:19:22 -05:00
parent b8a6aa2af6
commit e03d5861bb
2 changed files with 37 additions and 0 deletions

View File

@ -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;
};

View File

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