Re: error forward references if scope

2022-03-12 Thread Salih Dincer via Digitalmars-d-learn

On Saturday, 12 March 2022 at 13:12:25 UTC, vit wrote:

```d
enum touch_T = __traits(hasMember, T, "touch");
```


I think you meant build instead of touch?

```d
struct Query {
  public const SharedPtr!Builder builder;
}

interface Builder {
  void build(ref Query query);
}

struct SharedPtr(T) {
enum touch_T = __traits(hasMember, T, "build");
}

import std.traits, std.stdio;

void main() {
  Query q;
  q.builder.touch_T.writeln(" #build");
} // true #build
```


error forward references if scope

2022-03-12 Thread vit via Digitalmars-d-learn

Hello,
why this code compile without problems:

```d

struct Query{
public const SharedPtr!Builder builder;
}

interface Builder{
void build(ref Query query);
}

struct SharedPtr(T){
enum touch_T = __traits(hasMember, T, "touch");
//...
}


void main(){

}

```

but if `ref Query query` is scope then there is error?

```d

struct Query{
public const SharedPtr!Builder builder;
}

interface Builder{
void build(scope ref Query query); //SCOPE
}

struct SharedPtr(T){
enum touch_T = __traits(hasMember, T, "touch");
//...
}



void main(){

}
```

```
src/app.d(3,1): Error: no size because of forward references
src/app.d(4,18): Error: template instance 
`app.SharedPtr!(Builder)` error instantiating


```


Re: Forward references

2021-06-10 Thread Elmar via Digitalmars-d-learn

Hello there,

I got a weird compilation error which was hard to debug (even for 
just a little program) and I thought, this is quite related to 
this thread. This is my error message:


```
***search.d(42,1): Error: class ***.XXX has forward references
***box.d(21,32): Error: template instance *** error instantiating
***.d(16,2):instantiated from here: ...
...

```

It was odd, the fix was not obvious and the compiler didn't show 
me the place of the erroneous forward reference. The problem was 
a scoped `import` statement!! I had put the import statement for 
the Box class into the abstract base class Search, the only place 
where it is used, but this seems to cause a mess with many 
errors. The imported Box uses a sub class of Search as parameter 
type and since Search is extended by its subclasses it creates a 
circular reference in the subclass. The only way to fix was 
putting the import outside of the abstract base class (I assume 
because the import statement literally imports the Box together 
with the used subclass into Search itself).


The lesson is, you cannot put your import just everywhere.



Re: std.container.array: Error: unable to determine fields of Test because of forward references

2019-10-31 Thread Tobias Pankrath via Digitalmars-d-learn

On Thursday, 31 October 2019 at 12:37:55 UTC, user1234 wrote:

struct S
{
 S*[] children;
}

because otherwise when you declare the array the compiler has 
not finished the semantic ana of S.


---
struct Test
{
Test[] t;
}
---

Works today. Putting pointers into the container (and thus having 
another indirection) is not an option, though.


Re: std.container.array: Error: unable to determine fields of Test because of forward references

2019-10-31 Thread user1234 via Digitalmars-d-learn

On Thursday, 31 October 2019 at 12:37:55 UTC, user1234 wrote:
On Thursday, 31 October 2019 at 12:29:28 UTC, Tobias Pankrath 
wrote:

[...]


Try

struct S
{
 S*[] children;
}

because otherwise when you declare the array the compiler has 
not finished the semantic ana of S.


so S size is not known while S* size is known as it's a pointer


Re: std.container.array: Error: unable to determine fields of Test because of forward references

2019-10-31 Thread user1234 via Digitalmars-d-learn
On Thursday, 31 October 2019 at 12:29:28 UTC, Tobias Pankrath 
wrote:

My Problem:

--- (https://run.dlang.io/is/CfLscj)
import std.container.array;
import std.traits;

struct Test
{
   Test[] t;
}

struct Test2
{
   Array!Test2 t;
}

int main()
{
return FieldTypeTuple!Test.length + FieldTypeTuple!Test2;
}
---

I've found https://issues.dlang.org/show_bug.cgi?id=19407 but I 
am not using separate compilation, just `dmd test.d`.


I want to have a tree structure like

---
struct S
{
S[] children;
}
---

but I do not want to rely on the GC and thus wanted to use a 
custom array type. What's the best way to do this?


Try

struct S
{
 S*[] children;
}

because otherwise when you declare the array the compiler has not 
finished the semantic ana of S.


std.container.array: Error: unable to determine fields of Test because of forward references

2019-10-31 Thread Tobias Pankrath via Digitalmars-d-learn

My Problem:

--- (https://run.dlang.io/is/CfLscj)
import std.container.array;
import std.traits;

struct Test
{
   Test[] t;
}

struct Test2
{
   Array!Test2 t;
}

int main()
{
return FieldTypeTuple!Test.length + FieldTypeTuple!Test2;
}
---

I've found https://issues.dlang.org/show_bug.cgi?id=19407 but I 
am not using separate compilation, just `dmd test.d`.


I want to have a tree structure like

---
struct S
{
S[] children;
}
---

but I do not want to rely on the GC and thus wanted to use a 
custom array type. What's the best way to do this?


Re: class X has forward references

2018-06-12 Thread Ali Çehreli via Digitalmars-d-learn

On 06/12/2018 01:14 PM, bauss wrote:
> What could cause that error?

Could be this point apparently during semantic analysis:


https://github.com/dlang/dmd/blob/4e35f945e3245467c7ae0abe60fc3ec896c8b45f/src/dmd/semantic2.d#L576

private extern(C++) final class Semantic2Visitor : Visitor
{
// ...

override void visit(AggregateDeclaration ad)
{
//printf("AggregateDeclaration::semantic2(%s) type = %s, errors 
= %d\n", ad.toChars(), ad.type.toChars(), ad.errors);

if (!ad.members)
return;

if (ad._scope)
{
ad.error("has forward references");
return;
}

// ...
}
}

Does that mean that the scope pointer is already set when this 
AggregateDeclaration is being visited? If it's a bug, perhaps someone 
can think of a way of reproducing it.


Ali



Re: class X has forward references

2018-06-12 Thread bauss via Digitalmars-d-learn
On Tuesday, 12 June 2018 at 20:30:22 UTC, Steven Schveighoffer 
wrote:

On 6/12/18 4:14 PM, bauss wrote:

What could cause that error?

I cannot find anything in the documentation nor does the error 
message itself give much information.


A forward reference that can't be figured out by the compiler. 
This is one of the DMD front end's real weak spots.


I can't really give a good example, but I can tell as much as 
I have a few inheritances of classes using templates.


Yes, I've had weird forward reference errors in the past, and 
the only way I've been able to solve them is to move stuff 
around.



I just don't think that would be the issue.

When I try to make a minimized example it doesn't happen, so 
I'm going to assume it's either a function or a member or 
something in one of the inheritances that does it.


It would be really helpful if I knew what I was looking for, 
because it's thousands of lines of code I have to dig through 
with trial and error.


Have you tried dustmite?

I would think at least it should print the symbol it's not able 
to resolve.


-Steve


Yeah I get the symbol that it cannot resolve.

I'm moving stuff around now and the error has disappeared.

Now I just have to fix all the errors related to moving stuff 
around.


Thanks though!


Re: class X has forward references

2018-06-12 Thread Steven Schveighoffer via Digitalmars-d-learn

On 6/12/18 4:14 PM, bauss wrote:

What could cause that error?

I cannot find anything in the documentation nor does the error message 
itself give much information.


A forward reference that can't be figured out by the compiler. This is 
one of the DMD front end's real weak spots.


I can't really give a good example, but I can tell as much as I have a 
few inheritances of classes using templates.


Yes, I've had weird forward reference errors in the past, and the only 
way I've been able to solve them is to move stuff around.



I just don't think that would be the issue.

When I try to make a minimized example it doesn't happen, so I'm going 
to assume it's either a function or a member or something in one of the 
inheritances that does it.


It would be really helpful if I knew what I was looking for, because 
it's thousands of lines of code I have to dig through with trial and error.


Have you tried dustmite?

I would think at least it should print the symbol it's not able to resolve.

-Steve


class X has forward references

2018-06-12 Thread bauss via Digitalmars-d-learn

What could cause that error?

I cannot find anything in the documentation nor does the error 
message itself give much information.


I can't really give a good example, but I can tell as much as I 
have a few inheritances of classes using templates.


I just don't think that would be the issue.

When I try to make a minimized example it doesn't happen, so I'm 
going to assume it's either a function or a member or something 
in one of the inheritances that does it.


It would be really helpful if I knew what I was looking for, 
because it's thousands of lines of code I have to dig through 
with trial and error.


Re: Forward references

2018-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/25/18 6:53 PM, Jiyan wrote:

On Sunday, 25 February 2018 at 22:20:13 UTC, Steven Schveighoffer wrote:

On 2/25/18 4:25 PM, Jiyan wrote:

[...]


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


2.077.0

It is really strange, it works now but there still seems to be some 
strangeness about forward references.


There are frequently issues with forward references. They are supposed 
to always work, but it's not always the case.


-Steve


Re: Forward references

2018-02-25 Thread Jiyan via Digitalmars-d-learn
On Sunday, 25 February 2018 at 22:20:13 UTC, Steven Schveighoffer 
wrote:

On 2/25/18 4:25 PM, Jiyan wrote:

[...]


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


2.077.0

It is really strange, it works now but there still seems to be 
some strangeness about forward references.


Thanks till now i guess :P


Re: Forward references

2018-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/25/18 4:25 PM, Jiyan wrote:

Hi,
is there any document or text describing forward references?
It is kinda strange, i implemented a list structure which is kinda like 
this:


struct list(T)
{
private:

struct node
{
T val;
node* next;
node* prev;
}

node* head;
node* last;
size_t size;

  .
}

The thing is when i implement following struct:

struct Tre
{
list!Tre a;
}

theoretically it should be constructable. But it gives me out a compiler 
error about Forward reference. Ok maybe the compiler at this point cant 
do that but ...


The strange thing is i somehow managed earlier without knowing to do 
exactly this in a much more complicated struct.

Can somebody enlighten me about this?


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


Re: Forward references

2018-02-25 Thread ketmar via Digitalmars-d-learn

works for me with 2.076.


Forward references

2018-02-25 Thread Jiyan via Digitalmars-d-learn

Hi,
is there any document or text describing forward references?
It is kinda strange, i implemented a list structure which is 
kinda like this:


struct list(T)
{
private:

struct node
{
T val;
node* next;
node* prev;
}

node* head;
node* last;
size_t size;

 .
}

The thing is when i implement following struct:

struct Tre
{
list!Tre a;
}

theoretically it should be constructable. But it gives me out a 
compiler error about Forward reference. Ok maybe the compiler at 
this point cant do that but ...


The strange thing is i somehow managed earlier without knowing to 
do exactly this in a much more complicated struct.

Can somebody enlighten me about this?







Forward References

2016-06-27 Thread Jonathan Marler via Digitalmars-d-learn
Do the various D compilers use multiple passes to handle forward 
references or some other technique?


Re: Forward references and more

2009-10-12 Thread bearophile
 T.sizeof must be 8 in all cases.

Ignore this line, please :-)


Re: Forward references and more

2009-10-12 Thread Steven Schveighoffer
On Mon, 12 Oct 2009 05:26:58 -0400, bearophile bearophileh...@lycos.com  
wrote:



What's wrong with this code?

struct MemoryPool(T) {
alias T[100_000 / T.sizeof] Chunk;
Chunk*[] chunks;
}
struct Foo {
int x;
MemoryPool!(Foo) pool;
}
void main() {}

It prints Error: struct problem.Foo no size yet for forward reference.
T.sizeof must be 8 in all cases.


So I have tried to pull pool out:

struct MemoryPool(T) {
alias T[100_000 / T.sizeof] Chunk;
Chunk*[] chunks;
}
MemoryPool!(Foo) pool;
struct Foo {
int x;
// here uses pool
}
void main() {}

But there's a problem still:
Error: struct problem2.Foo no size yet for forward reference

To compile the code I have to move pool forward still:

struct MemoryPool(T) {
alias T[100_000 / T.sizeof] Chunk;
Chunk*[] chunks;
}
struct Foo {
int x;
// here uses pool
}
MemoryPool!(Foo) pool;
void main() {}

When possible it's better to avoid global variables. To avoid the global  
variable I may pass the instance pool to Foo. But to do this Foo has to  
become a struct template. But I am not sure how I can do this.

Do you have any comments or suggestions?


It looks strange what you are doing.  A Foo can have a memory pool of a  
lot of Foo's?  Do you mean to make the memory pool static?  I think that  
might work.


I think the main problem is you are defining MemoryPool!(Foo).Chunk which  
specifically needs to know the size of Foo before Foo is completely  
declared.


It's like you are doing this:

struct X
{
  X x;
}

Which clearly is incorrect.

-Steve


Re: Forward references and more

2009-10-12 Thread Ary Borenszweig

Steven Schveighoffer wrote:
On Mon, 12 Oct 2009 05:26:58 -0400, bearophile 
bearophileh...@lycos.com wrote:



What's wrong with this code?

struct MemoryPool(T) {
alias T[100_000 / T.sizeof] Chunk;
Chunk*[] chunks;
}
struct Foo {
int x;
MemoryPool!(Foo) pool;
}
void main() {}

It prints Error: struct problem.Foo no size yet for forward reference.
T.sizeof must be 8 in all cases.


The compiler does this:

Instantiate MemoryPool!(Foo)
But for that it needs to know Foo.sizeof.
But for that it needs to know MemoryPool!(Foo).sizeof.
But for that it needs to instantiate MemoryPool!(Foo) and find it's size.
etc.

I can see MemoryPool!(Foo) sizeof doesn't depend at all of T.sizeof 
because it just has a pointer. But how do you suggest to fix the 
compiler to understand that?


What I can see is that to know MemoryPool!(Foo).sizeof the type of the 
alias doesn't need to be solved completely... but what would you 
recommend the compiler to do?


Re: Forward references and more

2009-10-12 Thread bearophile
Ary Borenszweig:

 I can see MemoryPool!(Foo) sizeof doesn't depend at all of T.sizeof 
 because it just has a pointer.

Well, a dynamic array of pointers, but the situation is the same.


But how do you suggest to fix the compiler to understand that?

I don't know. I don't know enough about compilers.


 What I can see is that to know MemoryPool!(Foo).sizeof the type of the 
 alias doesn't need to be solved completely... but what would you 
 recommend the compiler to do?

To see what I can see. And terminate this little dance.
If that's not possible, then I'd like to have a syntax to give the necessary 
hint to the (less than smart) compiler. For example saying the size of one or 
both structs.

This was just an example, but it's not the first time I fall in this problem 
when I create data structures in D.

Bye and thank you,
bearophile


Re: Forward references and more

2009-10-12 Thread Steven Schveighoffer
On Mon, 12 Oct 2009 15:38:07 -0400, bearophile bearophileh...@lycos.com  
wrote:



Steven Schveighoffer:


It looks strange what you are doing.  A Foo can have a memory pool of a
lot of Foo's?  Do you mean to make the memory pool static?


Right and yes.



I think that might work.


It works if I use a global variable. But I'd like to not used global  
variables when possible.


A static variable is essentially a scoped global variable.  I think it  
will work if you make it static.  I've used plenty of static variables  
that are instances of the struct they are declared in.





I think the main problem is you are defining MemoryPool!(Foo).Chunk  
which

specifically needs to know the size of Foo before Foo is completely
declared.
It's like you are doing this:
struct X
{
   X x;
}
Which clearly is incorrect.


But MemoryPool.sizeof is always 8 (on a 32 bit system) because an alias  
takes no space. So T.sizeof must be 12. I'd like the compiler to  
understand this.


But you are also declaring the type of the chunk.  I don't think it would  
complain if you were not trying to define a type that required the size of  
Foo.  For example, if you did something like:


struct MemoryPool(T)
{
  T[] chunks;
}

I think it would work, because you aren't trying to define a type which  
*requires* the size of T before T is fully declared.  It's sort of a  
chicken and egg thing.  But since I think you are implementing the memory  
pool incorrectly (it makes no sense for each instance of an item to have a  
pool of itself), you should reexamine what you are trying to do.


-Steve


Re: x has forward references

2009-08-16 Thread Jos van Uden
Jacob Carlborg Wrote:

 It works with dmd 1.045

Where to get it?

I also tried compiling derelict today. I finally managed to get past the error 
messages by using the dmd compiler that ships with tango. 1.033 if I remember 
correctly. The lib folder filled up nicely with files. Then I did a dsss 
install command. The libs now show up in the dsss/lib folder and there are .di 
files in the include/derelict folder.

So I tried to compile a little test.d

module derelicttest;

import derelict.opengl.gl;

void main()
{
DerelictGL.load();
}

The dsss.conf:

[*]
buildflags = -g -gc

[test.d]


I don't know what else to put in there. I'm compiling with dmd 1.046. And get 
the following message.

D:\Workshop\D\derelictdsss build
test.d = test
OPTLINK (R) for Win32  Release 8.00.1
Copyright (C) Digital Mars 1989-2004  All rights reserved.
D:\Workshop\D\dsss\lib\\DerelictGL.lib(gl)
 Error 42: Symbol Undefined _D6object9Exception5_ctorMFAaC9ExceptionZC9Exception
--- errorlevel 1
Command D:\Workshop\D\dsss\bin\rebuild.exe returned with code -1, aborting.
Error: Command failed, aborting.

If I try it with the 1.033 compiler that ships with tango the list of messages 
is similar but even longer.








Re: x has forward references

2009-08-16 Thread Jacob Carlborg

On 8/16/09 19:36, Jos van Uden wrote:

Jacob Carlborg Wrote:


It works with dmd 1.045


Where to get it?


http://www.digitalmars.com/d/1.0/changelog.html#new1_045


I also tried compiling derelict today. I finally managed to get past the error 
messages by using the dmd compiler that ships with tango. 1.033 if I remember 
correctly. The lib folder filled up nicely with files. Then I did a dsss 
install command. The libs now show up in the dsss/lib folder and there are .di 
files in the include/derelict folder.

So I tried to compile a little test.d

module derelicttest;

import derelict.opengl.gl;

void main()
{
 DerelictGL.load();
}

The dsss.conf:

[*]
buildflags = -g -gc

[test.d]


I don't know what else to put in there. I'm compiling with dmd 1.046. And get 
the following message.

D:\Workshop\D\derelictdsss build
test.d =  test
OPTLINK (R) for Win32  Release 8.00.1
Copyright (C) Digital Mars 1989-2004  All rights reserved.
D:\Workshop\D\dsss\lib\\DerelictGL.lib(gl)
  Error 42: Symbol Undefined 
_D6object9Exception5_ctorMFAaC9ExceptionZC9Exception
--- errorlevel 1
Command D:\Workshop\D\dsss\bin\rebuild.exe returned with code -1, aborting.
Error: Command failed, aborting.

If I try it with the 1.033 compiler that ships with tango the list of messages 
is similar but even longer.










Re: x has forward references

2009-08-16 Thread Jos van Uden
Spacen Jasset Wrote:

 Jos van Uden wrote:
  Jacob Carlborg Wrote:
  
  On 8/16/09 19:36, Jos van Uden wrote:
  Jacob Carlborg Wrote:
 
  It works with dmd 1.045
  Where to get it?
  http://www.digitalmars.com/d/1.0/changelog.html#new1_045
  
  Thank you. This version does indeed compile the libs, just like 1.033, but 
  I still get the same error when I try to compile the test. When I do the 
  DerelictAL test (alinfo) that comes with the derelict download, it compiles 
  and runs just fine.
  
  
 Try zapping all the derelict object and lib files.

That did the trick. Thanks.


Re: x has forward references

2009-08-13 Thread Jacob Carlborg

On 8/13/09 17:01, Spacen Jasset wrote:

Hello, trying to use deteclit with the latest version of dmd 1.047

and I get this error. I don't understand what it means:



derelict\freetype\fttypes.d(827): Error: struct
derelict.freetype.fttypes.FT_RasterRec has forward references


line 97: alias FT_RasterRec* FT_Raster;
line 827: struct FT_RasterRec;


If use use dmd 1.046 it probably means you hit this bug: 
http://d.puremagic.com/issues/show_bug.cgi?id=3168


It works with dmd 1.045

/Jacob Carlborg