Showing with 23 additions and 3 deletions.
  1. +3 −3 src/func.c
  2. +20 −0 test/runnable/testcontracts.d
6 changes: 3 additions & 3 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -4367,14 +4367,14 @@ bool FuncDeclaration::hasNestedFrameRefs()
if (closureVars.dim)
return true;

/* If a virtual method has contracts, assume its variables are referenced
/* If a virtual function has contracts, assume its variables are referenced
* by those contracts, even if they aren't. Because they might be referenced
* by the overridden or overriding function's contracts.
* This can happen because frequire and fensure are implemented as nested functions,
* and they can be called directly by an overriding function and the overriding function's
* context had better match, or Bugzilla 7337 will bite.
* context had better match, or Bugzilla 7335 will bite.
*/
if ((fdrequire || fdensure) && isVirtualMethod())
if (fdrequire || fdensure)
return true;

if (foverrides.dim && isVirtualMethod())
Expand Down
20 changes: 20 additions & 0 deletions test/runnable/testcontracts.d
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,25 @@ class C10981
body {}
}

/*******************************************/
// 14779

class C14779
{
final void foo(int v)
in { assert(v == 0); }
out { assert(v == 0); }
body
{
}
}

void test14779()
{
auto c = new C14779();
c.foo(0);
}

/*******************************************/

int main()
Expand All @@ -772,6 +791,7 @@ int main()
test8073();
test8093();
test9383();
test14779();

printf("Success\n");
return 0;
Expand Down