1
0
Fork 0

[#19] Cannot declare virtual static methods

closure/master
Mike Gerwitz 2011-06-09 22:21:26 -04:00
parent 8b33471e42
commit adb7e088b7
2 changed files with 37 additions and 0 deletions

View File

@ -145,6 +145,15 @@ function validateMethod( keywords, prev_data, value, name )
); );
} }
// virtual static does not make sense, as static methods cannot be
// overridden
if ( keywords[ 'virtual' ] && ( keywords[ 'static' ] ) )
{
throw TypeError(
"Cannot declare static method '" + name + "' as virtual"
);
}
// search for any previous instances of this member // search for any previous instances of this member
if ( prev ) if ( prev )
{ {

View File

@ -182,6 +182,34 @@ mb_common.assertCommon();
} )(); } )();
/**
* Static methods cannot realistically be declared as virtual; it doesn't make
* sense. Virtual implies that the method may be overridden, but static methods
* cannot be overridden. Only hidden.
*/
( function testCannotDeclareStaticMethodsAsVirtual()
{
mb_common.value = function() {};
try
{
// attempt to build a virtual static method (should throw exception)
mb_common.buildMemberQuick( { 'static': true, 'virtual': true } );
}
catch ( e )
{
assert.ok(
e.message.search( mb_common.name ) !== -1,
"Method name should be provided in virtual static error message"
);
return;
}
assert.fail( "Should not be permitted to declare a virtual static method" );
} )();
/** /**
* To ensure interfaces of subtypes remain compatible with that of their * To ensure interfaces of subtypes remain compatible with that of their
* supertypes, the parameter lists must match and build upon each other. * supertypes, the parameter lists must match and build upon each other.