Permalink
Browse files

Merge pull request #2072 from 9rnsr/fix10148

[REG2.063a] Issue 10148 - unjustified 'safe function cannot call system function'
  • Loading branch information...
WalterBright committed May 24, 2013
2 parents 4023554 + cf3fa53 commit 59693a8e4e750f3848d415de6100c1b30082e3ef
Showing with 60 additions and 2 deletions.
  1. +22 −0 src/func.c
  2. +2 −2 src/mtype.c
  3. +36 −0 test/compilable/testInference.d
View
@@ -198,6 +198,28 @@ void FuncDeclaration::semantic(Scope *sc)
sc = sc->push();
sc->stc |= storage_class & STCdisable; // forward to function type
TypeFunction *tf = (TypeFunction *)type;
#if 1
/* If the parent is @safe, then this function defaults to safe
* too.
* If the parent's @safe-ty is inferred, then this function's @safe-ty needs
* to be inferred first.
*/
if (tf->trust == TRUSTdefault &&
!(//isFuncLiteralDeclaration() ||
parent->isTemplateInstance() ||
ad && ad->parent && ad->parent->isTemplateInstance()))
{
for (Dsymbol *p = sc->func; p; p = p->toParent2())
{ FuncDeclaration *fd = p->isFuncDeclaration();
if (fd)
{
if (fd->isSafeBypassingInference())
tf->trust = TRUSTsafe; // default to @safe
break;
}
}
}
#endif
if (tf->isref) sc->stc |= STCref;
if (tf->isnothrow) sc->stc |= STCnothrow;
if (tf->isproperty) sc->stc |= STCproperty;
View
@@ -5479,7 +5479,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
tf->isproperty = TRUE;
tf->linkage = sc->linkage;
#if 0
/* If the parent is @safe, then this function defaults to safe
* too.
* If the parent's @safe-ty is inferred, then this function's @safe-ty needs
@@ -5495,7 +5495,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
break;
}
}
#endif
bool wildreturn = FALSE;
if (tf->next)
{
@@ -281,6 +281,42 @@ class Node10002
}
}
/***************************************************/
// 10148
void fa10148() {} // fa is @system
auto fb10148(T)()
{
struct A(S)
{
// [4] Parent function fb is already inferred to @safe, then
// fc is forcely marked @safe on default until 2.052.
// But fc should keep attribute inference ability
// by overriding the inherited @safe-ty from its parent.
void fc(T2)()
{
// [5] During semantic3 process, fc is not @safe on default.
static assert(is(typeof(&fc) == void delegate()));
fa10148();
}
// [1] this is now inferred to @safe by implementing issue 7511
this(S a) {}
}
// [2] A!int(0) is now calling @safe function, then fb!T also be inferred to @safe
return A!int(0);
}
void test10148()
{
fb10148!int.fc!int; // [0] instantiate fb
// [3] instantiate fc
// [6] Afer semantic3 done, fc!int is deduced to @system.
static assert(is(typeof(&fb10148!int.fc!int) == void delegate() @system));
}
/***************************************************/
// Add more tests regarding inferences later.

0 comments on commit 59693a8

Please sign in to comment.