bug in pragma?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jul 4 15:38:51 PDT 2013


On Thu, Jul 04, 2013 at 03:35:09PM -0700, Jonathan M Davis wrote:
> On Friday, July 05, 2013 00:29:20 JS wrote:
> > import std.stdio, std.cstream;
> > 
> > 
> > template test(alias x)
> > {
> > 	string func()
> > 	{
> > 		string s = "beta";
> > 		//pragma(msg, s);
> > 		return s;
> > 	}
> > 	enum test = func();
> > }
> > 
> > void main(string[] args)
> > {
> > 	mixin test!("alpha");
> > 	din.getc();
> > }
> > 
> > When I try to display a compiler msg using pragma on a string
> > variable the mixin fails. Commenting out the pragma allows the
> > mixin to work.
> > 
> > While there may be some internal reason this shouldn't work it
> > seems quite unnatural and took me a while to figure out it was
> > pragma causing the problem in my code.
> 
> I wouldn't ever expect that pragma to work. pramga is a compile-time
> construct and requires compile-time arguments, whereas s is normal,
> local variable and not usable at compile-time except when the function
> it's in is called as part of CTFE. It would work if s were an enum,
> because the value of an enum must be known at compile time, but that's
> not the case with a normal string variable.
[...]

Fair enough, but in this case, couldn't the compiler figure out that in
this case s must always be known at compile-time? Since otherwise, it's
not possible for enum test to work. Granted, this may not be something
implementable, since it looks suspiciously similar to solving the
halting problem.


T

-- 
It is impossible to make anything foolproof because fools are so ingenious. -- Sammy


More information about the Digitalmars-d mailing list