www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3252] New: undefined reference to package function called from an interface

reply d-bugmail puremagic.com writes:
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:

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: -------
Aug 16 2009
next sibling parent d-bugmail puremagic.com writes:
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



---
Same problem on windows

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3252




---
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: -------
Jan 24 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Sep 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jan 22 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3252




---
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: -------
Jan 25 2013