Thread overview | |||||
---|---|---|---|---|---|
|
August 21, 2019 strangely silent compiler | ||||
---|---|---|---|---|
| ||||
I've: ``` module anomalo.util; // Foo doesn't exist anywhere!!!!! Foo toJsJson(string type, Args...)(string id, Args args) { static if (type == "int" || type == "outcome") { return Json(["id" : Json(id), "type" : Json(type), "value" : Json(0),]); } else { static assert(0, "invalid type"); } } ``` So: ``` $ dub build ``` No error! ``` $ /usr/bin/dmd -lib -ofliba.a -debug -g -w -I. src/anomalo/util.d -vcolumns ``` No error! Here [github](https://github.com/o3o/anomalo) my project. Thank you |
August 21, 2019 Re: strangely silent compiler | ||||
---|---|---|---|---|
| ||||
Posted in reply to Orfeo | On Wednesday, 21 August 2019 at 13:41:20 UTC, Orfeo wrote:
> I've:
> ```
> module anomalo.util;
>
> // Foo doesn't exist anywhere!!!!!
>
> Foo toJsJson(string type, Args...)(string id, Args args) {
> static if (type == "int" || type == "outcome") {
> return Json(["id" : Json(id), "type" : Json(type), "value" : Json(0),]);
> } else {
> static assert(0, "invalid type");
> }
> }
>
> ```
>
> So:
> ```
> $ dub build
> ```
> No error!
>
> ```
> $ /usr/bin/dmd -lib -ofliba.a -debug -g -w -I. src/anomalo/util.d -vcolumns
> ```
>
> No error!
>
> Here [github](https://github.com/o3o/anomalo) my project.
>
> Thank you
toJsJson is a template. Templates are evaluated first when they are instantiated. Compiler doesn't give an error because it doesn't compile toJsJson, because you don't instantiate it anywhere.
|
August 21, 2019 Re: strangely silent compiler | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eugene Wissner | On Wednesday, 21 August 2019 at 13:56:51 UTC, Eugene Wissner wrote:
> On Wednesday, 21 August 2019 at 13:41:20 UTC, Orfeo wrote:
>> I've:
>> ```
>> module anomalo.util;
>>
>> // Foo doesn't exist anywhere!!!!!
>>
>> Foo toJsJson(string type, Args...)(string id, Args args) {
>> static if (type == "int" || type == "outcome") {
>> return Json(["id" : Json(id), "type" : Json(type), "value" : Json(0),]);
>> } else {
>> static assert(0, "invalid type");
>> }
>> }
>>
>> ```
>>
>> So:
>> ```
>> $ dub build
>> ```
>> No error!
>>
>> ```
>> $ /usr/bin/dmd -lib -ofliba.a -debug -g -w -I. src/anomalo/util.d -vcolumns
>> ```
>>
>> No error!
>>
>> Here [github](https://github.com/o3o/anomalo) my project.
>>
>> Thank you
>
> toJsJson is a template. Templates are evaluated first when they are instantiated. Compiler doesn't give an error because it doesn't compile toJsJson, because you don't instantiate it anywhere.
You're right: if I add (into util.d)
```
unittest {
import std.stdio;
writeln(toJsJson!"int"("a"));
}
```
voila' :
```
$ dub test
src/anomalo/util.d(3,5): Error: undefined identifier Foo
src/anomalo/util.d(13,26): Error: template instance `anomalo.util.toJsJson!"int"` error instantiating
/usr/bin/dmd failed with exit code 1.
```
Thank you
|
Copyright © 1999-2021 by the D Language Foundation