Abstract methods of subtypes overriding abstract methods must be compatiable with the previous definition
parent
2e8097e21e
commit
2e930482d2
23
lib/util.js
23
lib/util.js
|
@ -255,17 +255,19 @@ function method_override(
|
||||||
throw new TypeError( "Cannot override method with non-method" );
|
throw new TypeError( "Cannot override method with non-method" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we were given a concrete method to an abstract method,
|
if ( abstract_map[ name ] !== undefined )
|
||||||
// then the method should no longer be considered abstract
|
|
||||||
if ( ( abstract_map[ name ] !== undefined )
|
|
||||||
&& ( exports.isAbstractMethod( new_method.abstractFlag ) === false )
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
var is_abstract = exports.isAbstractMethod( new_method );
|
||||||
|
|
||||||
if ( super_method.definition instanceof Array )
|
if ( super_method.definition instanceof Array )
|
||||||
{
|
{
|
||||||
|
var arg_len = ( is_abstract )
|
||||||
|
? new_method.definition.length
|
||||||
|
: new_method.length;
|
||||||
|
|
||||||
// ensure the concrete definition is compatible with
|
// ensure the concrete definition is compatible with
|
||||||
// that of its supertype
|
// that of its supertype
|
||||||
if ( new_method.length < super_method.definition.length )
|
if ( arg_len < super_method.definition.length )
|
||||||
{
|
{
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Declaration of " + name + " must be compatiable" +
|
"Declaration of " + name + " must be compatiable" +
|
||||||
|
@ -274,8 +276,13 @@ function method_override(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete abstract_methods[ abstract_map[ name ] ];
|
// if this was a concrete method, then it should no longer be marked as
|
||||||
data.abstractModified = true;
|
// abstract
|
||||||
|
if ( is_abstract === false )
|
||||||
|
{
|
||||||
|
delete abstract_methods[ abstract_map[ name ] ];
|
||||||
|
data.abstractModified = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the method that will be invoked when the requested
|
// this is the method that will be invoked when the requested
|
||||||
|
|
|
@ -172,6 +172,30 @@ assert.throws( function()
|
||||||
});
|
});
|
||||||
}, Error, "Concrete methods must implement the proper number of argments" );
|
}, Error, "Concrete methods must implement the proper number of argments" );
|
||||||
|
|
||||||
|
assert.throws( function()
|
||||||
|
{
|
||||||
|
AbstractFoo.extend(
|
||||||
|
{
|
||||||
|
// incorrect number of arguments
|
||||||
|
method: abstractMethod(),
|
||||||
|
});
|
||||||
|
}, Error, "Abstract methods of subtypes must implement the proper number of argments" );
|
||||||
|
|
||||||
|
assert.doesNotThrow(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
AbstractFoo.extend(
|
||||||
|
{
|
||||||
|
// incorrect number of arguments
|
||||||
|
method: abstractMethod( 'one', 'two', 'three', 'four' ),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
Error,
|
||||||
|
"Abstract methods of subtypes may implement additional arguments, so long" +
|
||||||
|
"as they implement at least the required number of arguments as defined by " +
|
||||||
|
"it supertype"
|
||||||
|
);
|
||||||
|
|
||||||
assert.doesNotThrow(
|
assert.doesNotThrow(
|
||||||
function()
|
function()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue