Skip to content

Commit

Permalink
3581 "private" attribute breaks "override"
Browse files Browse the repository at this point in the history
It's slightly more general than in the bug report: any non-virtual function
cannot use override.
  • Loading branch information
Don Clugston committed Mar 1, 2011
1 parent c5828e9 commit 9f7b2f8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ void FuncDeclaration::semantic(Scope *sc)
if (isAbstract() && !isVirtual())
error("non-virtual functions cannot be abstract");

if (isOverride() && !isVirtual())
error("cannot override a non-virtual function");

if ((f->isConst() || f->isImmutable()) && !isThis())
error("without 'this' cannot be const/immutable");

Expand Down

2 comments on commit 9f7b2f8

@WalterBright
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing this causes the following failure compiling phobos:

std\typecons.d(1581): Error: constructor std.typecons.AutoImplement!(C,generateEmptyFunction,isAbstractFunction).AutoImplement.this cannot override a non-virtual function

The code in question is:

class AutoImplement(Base, alias how, alias what = isAbstractFunction) : Base
{
private alias AutoImplement_Helper!(
"autoImplement_helper_", "Base", Base, how, what )
autoImplement_helper_;
override mixin(autoImplement_helper_.code);
}

Until what to do about this is figured out, I can't merge this in.

@rainers
Copy link

@rainers rainers commented on 9f7b2f8 May 6, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I happen to have the patch installed, I stumbled over this problem today when running the unittests. The problem is that the "override" sets the attribute for the complete mixin, including auto-implemented constructors.

Here's a patch that moves the override attribute to each generated function if it is not a constructor:

Left file: C:\Dokumente und Einstellungen\Rainer\Lokale Einstellungen\Temp\typ2F.d
Right file: M:\s\d\rainers\phobos\std\typecons.d

*** C:\Dokumente und Einstellungen\Rainer\Lokale Einstellungen\Temp\typ2F.d 2011-05-06 17:29:59.000000000 +-0200
--- M:\s\d\rainers\phobos\std\typecons.d 2011-05-06 09:10:49.000000000 +-0200
***************
*** 1590,1602 ****
   */
  class AutoImplement(Base, alias how, alias what = isAbstractFunction) : Base
  {
      private alias AutoImplement_Helper!(
              "autoImplement_helper_", "Base", Base, how, what )
               autoImplement_helper_;
!     override mixin(autoImplement_helper_.code);
  }

  /*
   * Code-generating stuffs are encupsulated in this helper template so that
   * namespace pollusion, which can cause name confliction with Base's public
   * members, should be minimized.
--- 1590,1602 ----
   */
  class AutoImplement(Base, alias how, alias what = isAbstractFunction) : Base
  {
      private alias AutoImplement_Helper!(
              "autoImplement_helper_", "Base", Base, how, what )
               autoImplement_helper_;
!     mixin(autoImplement_helper_.code);
  }

  /*
   * Code-generating stuffs are encupsulated in this helper template so that
   * namespace pollusion, which can cause name confliction with Base's public
   * members, should be minimized.
***************
*** 2078,2089 ****
--- 2078,2091 ----
                  if (is(Func == immutable)) postc ~= " immutable";
                  return postc;
              }
              enum storageClass = make_storageClass();

              //
+       if(isAbstractFunction!func)
+       code ~= "override ";
              code ~= Format!("extern(%s) %s %s(%s) %s %s\n",
                      functionLinkage!(func),
                      returnType,
                      realName,
                      ""~generateParameters!(myFuncInfo, func),
                      postAtts, storageClass );

Please sign in to comment.