www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cannot Instantiate Immutable or Constant Structure Variable

reply Loopback <elliott.darfink gmail.com> writes:
Hello!

Since I haven't received an answer for several days at the "learn"
newsgroup I was wondering if this was an error related to D or just
a hard nut to crack.

The unittest in this code is not compile-able, whereas the compiler
complains saying that the expression cannot be evaluated at compile
time (the constructor).

http://pastebin.com/CBJE24h1

I'm sorry if I seem impatient about creating a thread here, but my
development have come to a full halt because of this (seamlessly)
small problem.
Jul 05 2011
next sibling parent reply Jose Armando Garcia <jsancio gmail.com> writes:
First, you should always try to simplify the problem when asking for =20
help. Not many people want to read a lot of code to find the issue.

Second, I just glanced at the code and couldn't find a constructor =20
that takes 3 arguments (floats).



Em 05/07/2011, =C3=A0s 23:27, Loopback <elliott.darfink gmail.com> =
escreveu:

 Hello!

 Since I haven't received an answer for several days at the "learn"
 newsgroup I was wondering if this was an error related to D or just
 a hard nut to crack.

 The unittest in this code is not compile-able, whereas the compiler
 complains saying that the expression cannot be evaluated at compile
 time (the constructor).

 http://pastebin.com/CBJE24h1

 I'm sorry if I seem impatient about creating a thread here, but my
 development have come to a full halt because of this (seamlessly)
 small problem.

Jul 05 2011
parent reply Loopback <elliott.darfink gmail.com> writes:
On 2011-07-06 04:39, Jose Armando Garcia wrote:
 First, you should always try to simplify the problem when asking for
 help. Not many people want to read a lot of code to find the issue.

That's understandable indeed, though I haven't been able to distinguish what's the exact property of the structure that is causing this error, otherwise I would have gladly used a short sample.
 Secondly, I just glanced at the code and couldn't find a constructor that
 takes 3 arguments (floats).

How facile of me to forget. I've accidentally used the constructor of a nearly identic structure except that there is also an Z-axis (3d Vector). The two structures are practically the same except that one takes an additional parameter in the constructor (z-axis). The problem though, lies within both of these structures (presumably because they are so similar). None of them can be declared const or immutable. So do please ignore the last parameter.
Jul 05 2011
parent reply Loopback <elliott.darfink gmail.com> writes:
On 2011-07-06 08:20, Jens Mueller wrote:
 Loopback wrote:
 On 2011-07-06 04:39, Jose Armando Garcia wrote:
 First, you should always try to simplify the problem when asking for
 help. Not many people want to read a lot of code to find the issue.

That's understandable indeed, though I haven't been able to distinguish what's the exact property of the structure that is causing this error, otherwise I would have gladly used a short sample.

You may give DustMite a try. Maybe it can reduce it for you. https://github.com/CyberShadow/DustMite/wiki Jens

Thank you for the link! It was very useful. I've stripped lots of code and now, it seems too simple to not be able to figure out where the problem lies. I've always thought the error was related to templates, but as I said; it was much more simple. Perhaps the problem is obvious for those experienced in D but I am still a rookie. I've also searched for a solution but I have found none. struct DVector2 { float x, y; this(float x, float y) { this.x = x; this.y = y; } } void main(string[] args) { // Creating This Vector Fails // 'Error: cannot evaluate __ctmp3.this(0F, 1F) at compile time' static immutable DVector2 _test = DVector2(0f, 1f); // Same with variable within class C c = new C; } class C { // This code fails as well, with the same error immutable DVector2 _test = DVector2(0f, 1f); }
Jul 06 2011
parent reply Don <nospam nospam.com> writes:
Loopback wrote:
 On 2011-07-06 08:20, Jens Mueller wrote:
 Loopback wrote:
 On 2011-07-06 04:39, Jose Armando Garcia wrote:
 First, you should always try to simplify the problem when asking for
 help. Not many people want to read a lot of code to find the issue.

That's understandable indeed, though I haven't been able to distinguish what's the exact property of the structure that is causing this error, otherwise I would have gladly used a short sample.

You may give DustMite a try. Maybe it can reduce it for you. https://github.com/CyberShadow/DustMite/wiki Jens

Thank you for the link! It was very useful. I've stripped lots of code and now, it seems too simple to not be able to figure out where the problem lies. I've always thought the error was related to templates, but as I said; it was much more simple. Perhaps the problem is obvious for those experienced in D but I am still a rookie. I've also searched for a solution but I have found none.

It's a compiler CTFE bug, which has been fixed in the latest beta release (2.054).
Jul 06 2011
next sibling parent reply Loopback <elliott.darfink gmail.com> writes:
On 2011-07-06 16:56, Don wrote:
 It's a compiler CTFE bug, which has been fixed in the latest beta
 release (2.054).

I am in dire need for the beta release then I guess. Is it any mature, or what's even more important; where are the download mirrors/the repository?
Jul 06 2011
parent Jason House <jason.james.house gmail.com> writes:
Loopback Wrote:

 On 2011-07-06 16:56, Don wrote:
 It's a compiler CTFE bug, which has been fixed in the latest beta
 release (2.054).

I am in dire need for the beta release then I guess. Is it any mature, or what's even more important; where are the download mirrors/the repository?

Dmd and Phobos sources are on gitgub. The beta mailing list is dmd-beta puremagic.com. I don't have useful links handy, but that should be enough for you to find what you need. I think these are the work in progress beta download links: http://ftp.digitalmars.com/dmd1beta.zip http://ftp.digitalmars.com/dmd2beta.zip
Jul 06 2011
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On 2011-07-06 08:47, Loopback wrote:
 On 2011-07-06 16:56, Don wrote:
 It's a compiler CTFE bug, which has been fixed in the latest beta
 release (2.054).

I am in dire need for the beta release then I guess. Is it any mature, or what's even more important; where are the download mirrors/the repository?

If you want to try out dmd beta's then sign up for the dmd-beta list. The beta for 1.069 and 2.054 just started, and the URLs for the files are http://ftp.digitalmars.com/dmd1beta.zip http://ftp.digitalmars.com/dmd2beta.zip - Jonathan M davis
Jul 06 2011
prev sibling parent Jens Mueller <jens.k.mueller gmx.de> writes:
Loopback wrote:
 On 2011-07-06 04:39, Jose Armando Garcia wrote:
First, you should always try to simplify the problem when asking for
help. Not many people want to read a lot of code to find the issue.

That's understandable indeed, though I haven't been able to distinguish what's the exact property of the structure that is causing this error, otherwise I would have gladly used a short sample.

You may give DustMite a try. Maybe it can reduce it for you. https://github.com/CyberShadow/DustMite/wiki Jens
Jul 05 2011