Removed error on naked, not fully complete, but I'll be doing more work on it during this Christmas, and some things do work.

Fixed taking delegate of final class method. see mini/delegate3.d.
This commit is contained in:
Tomas Lindquist Olsen
2008-12-09 14:07:30 +01:00
parent 417aa57501
commit 3c400ff21c
4 changed files with 20 additions and 8 deletions

View File

@@ -1260,6 +1260,7 @@ LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl)
{
// sanity checks
assert(fdecl->isVirtual());
assert(!fdecl->isFinal());
assert(fdecl->vtblIndex > 0); // 0 is always ClassInfo/Interface*
assert(inst->getType()->toBasetype()->ty == Tclass);

View File

@@ -628,13 +628,6 @@ void DtoDefineFunc(FuncDeclaration* fd)
Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars());
LOG_SCOPE;
// error on naked
if (fd->naked)
{
fd->error("naked is not supported");
fatal();
}
// debug info
if (global.params.symdebug) {
Module* mo = fd->getModule();

View File

@@ -1970,7 +1970,7 @@ DValue* DelegateExp::toElem(IRState* p)
Logger::println("func: '%s'", func->toPrettyChars());
LLValue* castfptr;
if (func->isVirtual())
if (func->isVirtual() && !func->isFinal())
castfptr = DtoVirtualFunctionPointer(u, func);
else if (func->isAbstract())
assert(0 && "TODO delegate to abstract method");

18
tests/mini/delegate3.d Normal file
View File

@@ -0,0 +1,18 @@
module bar;
class S
{
int i;
final int foo()
{
return i;
}
}
void main()
{
auto s = new S;
s.i = 42;
auto dg = &s.foo;
assert(dg() == 42);
}