www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - BUG? Template problems - template1.d

reply D. Trebbien <D._member pathlink.com> writes:
Compiling the attached code gives these errors:

template1.d(3): template instance List!(int) List is not a template declaration,
it is a interface
template1.d(3): List!(int) is used as a type
template1.d(16): template instance template1.List!(int) error instantiating

Shouldn't this code compile?

----Attachment contents supplied below for reference----

interface List(E)
{
List!(E) sublist(int off, int len);
}

class Vector(E) : List!(E)
{
List!(E) sublist(int off, int len)
{
return null;
}
}

int main()
{
List!(int) lst=new Vector!(int);

return 0;
}


begin 0644 template1.d
M:6YT97)F86-E($QI<W0H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT



M:6XH*0T*>PT*("` 3&ES="$H:6YT*2!L<W0];F5W(%9E8W1O<B$H:6YT*3L-

`
end
Feb 27 2005
parent reply D. Trebbien <D._member pathlink.com> writes:
Does anyone know if this is really a bug?

In article <cvtoh8$16l3$1 digitaldaemon.com>, D. Trebbien says...
Compiling the attached code gives these errors:

template1.d(3): template instance List!(int) List is not a template declaration,
it is a interface
template1.d(3): List!(int) is used as a type
template1.d(16): template instance template1.List!(int) error instantiating

Shouldn't this code compile?

----Attachment contents supplied below for reference----

interface List(E)
{
List!(E) sublist(int off, int len);
}

class Vector(E) : List!(E)
{
List!(E) sublist(int off, int len)
{
return null;
}
}

int main()
{
List!(int) lst=new Vector!(int);

return 0;
}


begin 0644 template1.d
M:6YT97)F86-E($QI<W0H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT



M:6XH*0T*>PT*("` 3&ES="$H:6YT*2!L<W0];F5W(%9E8W1O<B$H:6YT*3L-

`
end
Mar 09 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
I dont think it's a bug. My understanding of the spec:

InterfaceDeclaration:
   interface Identifier InterfaceBody
   interface Identifier : SuperInterfaces InterfaceBody

SuperInterfaces
   Identifier
   Identifier , SuperInterfaces

InterfaceBody:
   { DeclDefs }

indicates that: "interface List(E)" isn't legal.

That said, how else can you achieve what you're after?

If you can't then this might be something we should consider adding to the  
spec.

Regan

On Wed, 9 Mar 2005 18:34:14 +0000 (UTC), D. Trebbien  
<D._member pathlink.com> wrote:
 Does anyone know if this is really a bug?

 In article <cvtoh8$16l3$1 digitaldaemon.com>, D. Trebbien says...
 Compiling the attached code gives these errors:

 template1.d(3): template instance List!(int) List is not a template  
 declaration,
 it is a interface
 template1.d(3): List!(int) is used as a type
 template1.d(16): template instance template1.List!(int) error  
 instantiating

 Shouldn't this code compile?

 ----Attachment contents supplied below for reference----

 interface List(E)
 {
 List!(E) sublist(int off, int len);
 }

 class Vector(E) : List!(E)
 {
 List!(E) sublist(int off, int len)
 {
 return null;
 }
 }

 int main()
 {
 List!(int) lst=new Vector!(int);

 return 0;
 }


 begin 0644 template1.d
 M:6YT97)F86-E($QI<W0H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT



 M:6XH*0T*>PT*("` 3&ES="$H:6YT*2!L<W0];F5W(%9E8W1O<B$H:6YT*3L-

 `
 end
Mar 09 2005
parent reply D. Trebbien <D._member pathlink.com> writes:
There wasn't anything specifically in the spec that would seem to allow this,
but if you comment out the line:
List!(E) sublist(int off, int len);
the code compiles and links without errors (new code attached).

What I wanted to do was create a class library in D for those who are familiar
with Java. The List interface is implemented by several different classes
(including the Vector class). E is a generic type. Basically, a List is a list
of values of the given type E. The Vector class implements a resizable List.

One of the functions of a List is to extract a subset of the List (a sublist),
given a starting index and length. The sublist is, of course, another List.

When I compiled this code with an earlier version of the D compiler, the
compiler mentioned "illegal forward reference," if that helps.

In article <opsnd5kfbk23k2f5 nrage.netwin.co.nz>, Regan Heath says...
I dont think it's a bug. My understanding of the spec:

InterfaceDeclaration:
   interface Identifier InterfaceBody
   interface Identifier : SuperInterfaces InterfaceBody

SuperInterfaces
   Identifier
   Identifier , SuperInterfaces

InterfaceBody:
   { DeclDefs }

indicates that: "interface List(E)" isn't legal.

That said, how else can you achieve what you're after?

If you can't then this might be something we should consider adding to the  
spec.

Regan

On Wed, 9 Mar 2005 18:34:14 +0000 (UTC), D. Trebbien  
<D._member pathlink.com> wrote:
 Does anyone know if this is really a bug?

 In article <cvtoh8$16l3$1 digitaldaemon.com>, D. Trebbien says...
 Compiling the attached code gives these errors:

 template1.d(3): template instance List!(int) List is not a template  
 declaration,
 it is a interface
 template1.d(3): List!(int) is used as a type
 template1.d(16): template instance template1.List!(int) error  
 instantiating

 Shouldn't this code compile?

 ----Attachment contents supplied below for reference----

 interface List(E)
 {
 List!(E) sublist(int off, int len);
 }

 class Vector(E) : List!(E)
 {
 List!(E) sublist(int off, int len)
 {
 return null;
 }
 }

 int main()
 {
 List!(int) lst=new Vector!(int);

 return 0;
 }


 begin 0644 template1.d
 M:6YT97)F86-E($QI<W0H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT



 M:6XH*0T*>PT*("` 3&ES="$H:6YT*2!L<W0];F5W(%9E8W1O<B$H:6YT*3L-

 `
 end
begin 0644 template1.d M:6YT97)F86-E($QI<W0H12D-"GL-"B` ("\O3&ES="$H12D <W5B;&ES="AI M;G0 ;V9F+"!I;G0 ;&5N*3L-"GT-" T*8VQA<W, 5F5C=&]R*$4I(#H 3&ES M="$H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT(&]F9BP :6YT(&QE ` end
Mar 09 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Thu, 10 Mar 2005 03:35:23 +0000 (UTC), D. Trebbien  
<D._member pathlink.com> wrote:
 There wasn't anything specifically in the spec that would seem to allow  
 this,
 but if you comment out the line:
 List!(E) sublist(int off, int len);
 the code compiles and links without errors (new code attached).
I'd say this is a bug. :) According to the spec.
 What I wanted to do was create a class library in D for those who are  
 familiar
 with Java. The List interface is implemented by several different classes
 (including the Vector class). E is a generic type. Basically, a List is  
 a list
 of values of the given type E. The Vector class implements a resizable  
 List.

 One of the functions of a List is to extract a subset of the List (a  
 sublist),
 given a starting index and length. The sublist is, of course, another  
 List.

 When I compiled this code with an earlier version of the D compiler, the
 compiler mentioned "illegal forward reference," if that helps.
Why not just use D's inbuilt array type? Regan
 In article <opsnd5kfbk23k2f5 nrage.netwin.co.nz>, Regan Heath says...
 I dont think it's a bug. My understanding of the spec:

 InterfaceDeclaration:
   interface Identifier InterfaceBody
   interface Identifier : SuperInterfaces InterfaceBody

 SuperInterfaces
   Identifier
   Identifier , SuperInterfaces

 InterfaceBody:
   { DeclDefs }

 indicates that: "interface List(E)" isn't legal.

 That said, how else can you achieve what you're after?

 If you can't then this might be something we should consider adding to  
 the
 spec.

 Regan

 On Wed, 9 Mar 2005 18:34:14 +0000 (UTC), D. Trebbien
 <D._member pathlink.com> wrote:
 Does anyone know if this is really a bug?

 In article <cvtoh8$16l3$1 digitaldaemon.com>, D. Trebbien says...
 Compiling the attached code gives these errors:

 template1.d(3): template instance List!(int) List is not a template
 declaration,
 it is a interface
 template1.d(3): List!(int) is used as a type
 template1.d(16): template instance template1.List!(int) error
 instantiating

 Shouldn't this code compile?

 ----Attachment contents supplied below for reference----

 interface List(E)
 {
 List!(E) sublist(int off, int len);
 }

 class Vector(E) : List!(E)
 {
 List!(E) sublist(int off, int len)
 {
 return null;
 }
 }

 int main()
 {
 List!(int) lst=new Vector!(int);

 return 0;
 }


 begin 0644 template1.d
 M:6YT97)F86-E($QI<W0H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT



 M:6XH*0T*>PT*("` 3&ES="$H:6YT*2!L<W0];F5W(%9E8W1O<B$H:6YT*3L-

 `
 end
Mar 09 2005
parent D. Trebbien <D._member pathlink.com> writes:
I could just use the array type, but that is not the point. This is somewhat an
exercise for testing D.

Maybe interfaces cannot be templates (and that is something that should be added
to the spec).

In article <opsneknodb23k2f5 nrage.netwin.co.nz>, Regan Heath says...
On Thu, 10 Mar 2005 03:35:23 +0000 (UTC), D. Trebbien  
<D._member pathlink.com> wrote:
 There wasn't anything specifically in the spec that would seem to allow  
 this,
 but if you comment out the line:
 List!(E) sublist(int off, int len);
 the code compiles and links without errors (new code attached).
I'd say this is a bug. :) According to the spec.
 What I wanted to do was create a class library in D for those who are  
 familiar
 with Java. The List interface is implemented by several different classes
 (including the Vector class). E is a generic type. Basically, a List is  
 a list
 of values of the given type E. The Vector class implements a resizable  
 List.

 One of the functions of a List is to extract a subset of the List (a  
 sublist),
 given a starting index and length. The sublist is, of course, another  
 List.

 When I compiled this code with an earlier version of the D compiler, the
 compiler mentioned "illegal forward reference," if that helps.
Why not just use D's inbuilt array type? Regan
 In article <opsnd5kfbk23k2f5 nrage.netwin.co.nz>, Regan Heath says...
 I dont think it's a bug. My understanding of the spec:

 InterfaceDeclaration:
   interface Identifier InterfaceBody
   interface Identifier : SuperInterfaces InterfaceBody

 SuperInterfaces
   Identifier
   Identifier , SuperInterfaces

 InterfaceBody:
   { DeclDefs }

 indicates that: "interface List(E)" isn't legal.

 That said, how else can you achieve what you're after?

 If you can't then this might be something we should consider adding to  
 the
 spec.

 Regan

 On Wed, 9 Mar 2005 18:34:14 +0000 (UTC), D. Trebbien
 <D._member pathlink.com> wrote:
 Does anyone know if this is really a bug?

 In article <cvtoh8$16l3$1 digitaldaemon.com>, D. Trebbien says...
 Compiling the attached code gives these errors:

 template1.d(3): template instance List!(int) List is not a template
 declaration,
 it is a interface
 template1.d(3): List!(int) is used as a type
 template1.d(16): template instance template1.List!(int) error
 instantiating

 Shouldn't this code compile?

 ----Attachment contents supplied below for reference----

 interface List(E)
 {
 List!(E) sublist(int off, int len);
 }

 class Vector(E) : List!(E)
 {
 List!(E) sublist(int off, int len)
 {
 return null;
 }
 }

 int main()
 {
 List!(int) lst=new Vector!(int);

 return 0;
 }


 begin 0644 template1.d
 M:6YT97)F86-E($QI<W0H12D-"GL-"B` ($QI<W0A*$4I('-U8FQI<W0H:6YT



 M:6XH*0T*>PT*("` 3&ES="$H:6YT*2!L<W0];F5W(%9E8W1O<B$H:6YT*3L-

 `
 end
Mar 10 2005