View mode: basic / threaded / horizontal-split · Log in · Help
July 06, 2011
Cannot Instantiate Immutable or Constant Structure Variable
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.
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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.

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



Em 05/07/2011, às 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.
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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.
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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);
}
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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).
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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?
July 06, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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
July 07, 2011
Re: Cannot Instantiate Immutable or Constant Structure Variable
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
Top | Discussion index | About this forum | D home