Bug 3252 – undefined reference to package function called from an interface

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2009-08-16T03:31:00Z
Last change time
2014-04-18T09:12:05Z
Keywords
link-failure
Assigned to
nobody
Creator
d

Comments

Comment #0 by d — 2009-08-16T03:31:36Z
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?
Comment #1 by d — 2009-08-17T00:04:34Z
Same problem with dmd-1.037, dmd-1.046, dmd-2.031, and ldc 0.9.1 (http://www.dsource.org/projects/ldc/ticket/354).
Comment #2 by aifgi90 — 2010-01-24T09:46:54Z
Same problem on windows
Comment #3 by d — 2010-01-24T11:49:07Z
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.
Comment #4 by verylonglogin.reg — 2012-09-23T22:21:31Z
And this isn't related to Issue 8716 because `a.packageFunc` module gives the same error.
Comment #5 by andrej.mitrovich — 2013-01-22T12:10:09Z
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).
Comment #6 by d — 2013-01-25T09:41:59Z
Agreed, except that I guess package (and private) functions should be legal in an interface in the first place.