Thread overview
"...cannot be interpreted at compile time" I can't find the source of the error!
Aug 20, 2021
Pablo De Nápoli
Aug 20, 2021
jfondren
Aug 20, 2021
Pablo De Nápoli
August 20, 2021

I am trying to write a D wrapper for libmpdec (https://www.bytereef.org/mpdecimal/).

I get the following message (compiling with dmd with -v and -verrros=context)

semantic2 cuenta
mpdec/decimal.d(35,20): Error: `mpd_new` cannot be interpreted at compile time, because it has no available source code
      value=mpd_new(&decimal_ctx);// constructor from int

caused by the following constructor...

class Decimal{

    mpd_t* value;


this(int x)
    {
      value=mpd_new(&decimal_ctx);// constructor from int
      mpd_set_i32(value, x, &decimal_ctx);
    }

 }

The problem is that I cannot figure out which line in my code causes this constructor
to be interpreted at compile time! It would be useful if dmd could print more specific
error messages.

Any idea of which could be the cause of trouble or on how to get more specific diagnosis?
Many thanks!

August 20, 2021

On Friday, 20 August 2021 at 02:30:53 UTC, Pablo De Nápoli wrote:

>

Any idea of which could be the cause of trouble or on how to get more specific diagnosis?

With no extra arguments I get a "compile time context created here" addendum. Does that not show up for you or does the line not make sense still?

It might also be new. This is with v2.097.1

example.d(6): Error: `atoi` cannot be interpreted at compile time, because it has no available source code
example.d(12):        compile time context created here
example.d(13): Error: no property `val` for type `void`

From this code:

extern (C) int atoi(const(char)* nptr);

class N {
    int val;
    this() {
        val = atoi("2");
    }
}

void main() {
    import std.stdio : writeln;
    enum n = new N(); // line 12
    writeln(n.val);
}
August 20, 2021

On Friday, 20 August 2021 at 02:51:16 UTC, jfondren wrote:

>

On Friday, 20 August 2021 at 02:30:53 UTC, Pablo De Nápoli wrote:

>

Any idea of which could be the cause of trouble or on how to get more specific diagnosis?

With no extra arguments I get a "compile time context created here" addendum. Does that not show up for you or does the line not make sense still?

It might also be new. This is with v2.097.1

example.d(6): Error: `atoi` cannot be interpreted at compile time, because it has no available source code
example.d(12):        compile time context created here
example.d(13): Error: no property `val` for type `void`

From this code:

extern (C) int atoi(const(char)* nptr);

class N {
    int val;
    this() {
        val = atoi("2");
    }
}

void main() {
    import std.stdio : writeln;
    enum n = new N(); // line 12
    writeln(n.val);
}

Many thanks!. I'm using the same version of the compiler.
Without arguments, I get

mpdec/decimal.d(35,20): Error: mpd_new cannot be interpreted at compile time, because it has no available source code
Error: cannot interpret <error> at compile time
mpdec/decimal.d(35,20): Error: mpd_new cannot be interpreted at compile time, because it has no available source code

Nothing like

"compile time context created here"

(this is what I would need to trace the error!)