diff --git a/gen/toir.cpp b/gen/toir.cpp index 483621ad14..38918a3f50 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2689,13 +2689,22 @@ DValue* FuncExp::toElem(IRState* p) assert(fd); + if (fd->tok == TOKreserved && type->ty == Tpointer) + { + // This is a lambda that was inferred to be a function literal instead + // of a delegate, so set tok here in order to get correct types/mangling. + // Horrible hack, but DMD does the same thing. + fd->tok = TOKfunction; + fd->vthis = NULL; + } + if (fd->isNested()) Logger::println("nested"); Logger::println("kind = %s", fd->kind()); fd->codegen(Type::sir); assert(fd->ir.irFunc->func); - if(fd->isNested() && !(fd->tok == TOKreserved && type->ty == Tpointer && fd->vthis)) { + if (fd->isNested()) { LLType* dgty = DtoType(type); LLValue* cval; @@ -2745,7 +2754,18 @@ LLConstant* FuncExp::toConstElem(IRState* p) LOG_SCOPE; assert(fd); - if (fd->tok != TOKfunction && !(fd->tok == TOKreserved && type->ty == Tpointer && fd->vthis)) + + if (fd->tok == TOKreserved && type->ty == Tpointer) + { + // This is a lambda that was inferred to be a function literal instead + // of a delegate, so set tok here in order to get correct types/mangling. + // Horrible hack, but DMD does the same thing in FuncExp::toElem and + // other random places. + fd->tok = TOKfunction; + fd->vthis = NULL; + } + + if (fd->tok != TOKfunction) { assert(fd->tok == TOKdelegate || fd->tok == TOKreserved); error("delegate literals as constant expressions are not yet allowed"); diff --git a/ir/irtype.cpp b/ir/irtype.cpp index 4d92eb47cc..324cbb2b66 100644 --- a/ir/irtype.cpp +++ b/ir/irtype.cpp @@ -164,6 +164,28 @@ IrTypePointer* IrTypePointer::get(Type* dt) } else { + if (dt->nextOf()->ty == Tfunction) + { + TypeFunction* tf = static_cast(dt->nextOf()); + if (tf->funcdecl) + { + if (FuncLiteralDeclaration* fld = + tf->funcdecl->isFuncLiteralDeclaration()) + { + if (fld->tok == TOKreserved) + { + // This is the type of a lambda that was inferred to be + // a function literal instead of a delegate, so set tok + // here in order to get correct types/mangling. Horrible + // hack, but DMD does the same thing in FuncExp::toElem + // and other random places. + fld->tok = TOKfunction; + fld->vthis = NULL; + } + } + } + } + elemType = DtoTypeNotVoid(dt->nextOf()); // DtoTypeNotVoid could have already created the same type, e.g. for