Thread overview
Using import in map
Jan 31, 2015
Jacob Carlborg
Jan 31, 2015
Stefan Koch
Jan 31, 2015
Jacob Carlborg
Feb 01, 2015
Dicebot
Feb 01, 2015
Daniel Murphy
Feb 01, 2015
Jacob Carlborg
Feb 01, 2015
Dicebot
January 31, 2015
Is this supposed to work:

enum foo = ["foo"].map!((string e) => import(e));

When I compile the above code with 2.066.1 I get the following error:

main.d(1): Error: variable e cannot be read at compile time
main.d(1): Error: file name argument must be a string, not (__error)

-- 
/Jacob Carlborg
January 31, 2015
On Saturday, 31 January 2015 at 19:52:11 UTC, Jacob Carlborg wrote:
> Is this supposed to work:
>
> enum foo = ["foo"].map!((string e) => import(e));
>
> When I compile the above code with 2.066.1 I get the following error:
>
> main.d(1): Error: variable e cannot be read at compile time
> main.d(1): Error: file name argument must be a string, not (__error)

I think this is not supposed to work.
try staticMap maybe ?

January 31, 2015
On 2015-01-31 20:54, Stefan Koch wrote:

> I think this is not supposed to work.
> try staticMap maybe ?

Yes, staticMap worked, thanks. I filed a bug [1]. If I recall correctly, if the compiler outputs a message which includes "__error" it's a bug.

[1]

-- 
/Jacob Carlborg
February 01, 2015
On Saturday, 31 January 2015 at 21:09:44 UTC, Jacob Carlborg wrote:
> On 2015-01-31 20:54, Stefan Koch wrote:
>
>> I think this is not supposed to work.
>> try staticMap maybe ?
>
> Yes, staticMap worked, thanks. I filed a bug [1]. If I recall correctly, if the compiler outputs a message which includes "__error" it's a bug.
>
> [1]

Is it? "__error" is simply a placeholder for type of expression that can't be deduced because of compilation error.

Original snippet shouldn't compiler because landa argument is run-time one but `import` must work at CT.
February 01, 2015
"Dicebot"  wrote in message news:jscikdikdbjxlkcwybtd@forum.dlang.org...

> Yes, staticMap worked, thanks. I filed a bug [1]. If I recall correctly, if the compiler outputs a message which includes "__error" it's a bug.

> Is it? "__error" is simply a placeholder for type of expression that can't be deduced because of compilation error.

Yeah, only the first error should be shown and the second should be supressed because it refers to an earlier error. 

February 01, 2015
On 2015-02-01 11:53, Dicebot wrote:

> Original snippet shouldn't compiler because landa argument is run-time
> one but `import` must work at CT.

It is resolved at compile time. Is this a CTFE vs CT problem?

-- 
/Jacob Carlborg
February 01, 2015
On Sunday, 1 February 2015 at 12:21:59 UTC, Jacob Carlborg wrote:
> On 2015-02-01 11:53, Dicebot wrote:
>
>> Original snippet shouldn't compiler because landa argument is run-time
>> one but `import` must work at CT.
>
> It is resolved at compile time. Is this a CTFE vs CT problem?

CTFE function is still considered runtime function in terms of restrictions because generally there is no way to tell what context it will be evaluated in. In this specific case it is clear but making use of it would require brand new language spec. Your code is similar to this:

int foo (string s) { pragma(msg, s); return 42; }

enum ct = foo("str");