Thread overview
[Issue 3252] New: undefined reference to package function called from an interface
Jan 24, 2010
Alexey Ivanov
Jan 24, 2010
Diggory
Sep 24, 2012
Denis Shelomovskij
Jan 22, 2013
Andrej Mitrovic
Jan 25, 2013
Diggory
August 16, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3252

           Summary: undefined reference to package function called from an
                    interface
           Product: D
           Version: 1.045
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Keywords: link-failure
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: diggory.hardy@gmail.com


When attempting to call a function with package protection level from an interface, I get an undefined reference error.


Code:

/** Compiler error - calling a package interface function.
 */
module packageFunc;

interface I {
    package void iPack();
}
class A : I {
    package void iPack() {}
}

void main () {
    A a = new A;
    I i = a;
    i.iPack;    // causes an undefined reference
    (cast(A) i).iPack;  // a workaround
}


The linker error:
# dmd packageFunc.d
packageFunc.o: In function `_Dmain':
packageFunc.d:(.text._Dmain+0x22): undefined reference to
`_D11packageFunc1I5iPackMFZv'
collect2: ld returned 1 exit status
--- errorlevel 1


Possibly similar to bug 2894.

This just bit me when including package protection to a lot of class functions in order to implement invariant tests (where package protection is the only applicable type of protection). I presume it's a bug; haven't tested if it's also the case with dmd 2.0 or other compilers yet. Any idea if it would be simple to fix?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3252


Alexey Ivanov <aifgi90@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aifgi90@gmail.com
         OS/Version|Linux                       |All


--- Comment #2 from Alexey Ivanov <aifgi90@gmail.com> 2010-01-24 09:46:54 PST ---
Same problem on windows

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3252



--- Comment #3 from Diggory <diggory.hardy@gmail.com> 2010-01-24 11:49:07 PST ---
It shouldn't be platform specific anyway, but thanks for confirming it also affects you.

Sorry, I guess this should have been linked to bug 3258.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3252


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg@gmail.com


--- Comment #4 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-09-24 09:21:31 MSD ---
And this isn't related to Issue 8716 because `a.packageFunc` module gives the same error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3252


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich@gmail.com
         Resolution|                            |INVALID


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-22 12:10:09 PST ---
package methods are non-virtual, so you're not overriding iPack here but instead introducing a new function in the 'A' class. 'I.pack' is an externally defined final function, which is why linking fails. If you define a body for 'I.pack' you will see that the compiler won't complain about an interface method having an implementation, because package (i.e. non-virtual) methods are allowed in interfaces.

The compiler currently doesn't complain about having a function in the base class (or interface) having the same name as the one defined in the current class:

class B
{
    package void iPack()
    {
    }
}

class A : B
{
    package void iPack()  // no errors, neither in D1 or D2
    {
    }
}

But that is a separate issue which would be an enhancement request (I think there are some opened ones about this).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3252



--- Comment #6 from Diggory <diggory.hardy@gmail.com> 2013-01-25 09:41:59 PST ---
Agreed, except that I guess package (and private) functions should be legal in an interface in the first place.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------