Re: Strange error
On Monday, 22 March 2021 at 07:52:14 UTC, MichaelJames wrote: Tell me, did you manage to solve this problem? https://github.com/dlang/dmd/pull/12300
Re: Strange error
On Sunday, 21 March 2021 at 07:18:10 UTC, Jack Applegame wrote: Could someone please explain what is wrong with this code? https://glot.io/snippets/fwxn2198kv ```d import std.stdio; struct Sample{ void function() func1; void function() func2; } void noth(Sample smpl)() { smpl.func1(); // Error: expression __lambda1 is not a valid template value argument smpl.func2(); // Error: expression __lambda2 is not a valid template value argument } void main(){ enum s = Sample( {writeln("Hello world1");}, {writeln("Hello world2");} ); s.func1(); s.func2(); noth!(s)(); } ``` Tell me, did you manage to solve this problem?
Re: Strange error
On 3/21/21 3:18 AM, Jack Applegame wrote: Could someone please explain what is wrong with this code? https://glot.io/snippets/fwxn2198kv ```d import std.stdio; struct Sample{ void function() func1; void function() func2; } void noth(Sample smpl)() { smpl.func1(); // Error: expression __lambda1 is not a valid template value argument smpl.func2(); // Error: expression __lambda2 is not a valid template value argument } void main(){ enum s = Sample( {writeln("Hello world1");}, {writeln("Hello world2");} ); s.func1(); s.func2(); noth!(s)(); } ``` You have the wrong lines attributed with the error message. The error message is in the assignment of s (line 15 and 16) Essentially, you can't use lambda functions as compile-time values. Valid template value parameters are [1] "any type which can be statically initialized at compile time. Template value arguments can be integer values, floating point values, nulls, string values, array literals of template value arguments, associative array literals of template value arguments, or struct literals of template value arguments." Now, one might argue that it's possible to statically initialize function pointers at compile time (i.e. you can do this as a static initialized function pointer at module scope), so possibly this is something that can be fixed. There might already be a bug report on it, or you can file one. It might end up with the spec being clarified to explicitly cover this case. -Steve [1] https://dlang.org/spec/template.html#template_value_parameter
Re: Strange error
On Sunday, 21 March 2021 at 08:45:19 UTC, Imperatorn wrote: On Sunday, 21 March 2021 at 07:18:10 UTC, Jack Applegame wrote: Could someone please explain what is wrong with this code? https://glot.io/snippets/fwxn2198kv ```d import std.stdio; struct Sample{ void function() func1; void function() func2; } void noth(Sample smpl)() { smpl.func1(); // Error: expression __lambda1 is not a valid template value argument smpl.func2(); // Error: expression __lambda2 is not a valid template value argument } void main(){ enum s = Sample( {writeln("Hello world1");}, {writeln("Hello world2");} ); s.func1(); s.func2(); noth!(s)(); } ``` https://forum.dlang.org/thread/mggbomxhjpglltsih...@forum.dlang.org There are no non-global templates in my snippet.
Re: Strange error
On Sunday, 21 March 2021 at 07:18:10 UTC, Jack Applegame wrote: Could someone please explain what is wrong with this code? https://glot.io/snippets/fwxn2198kv ```d import std.stdio; struct Sample{ void function() func1; void function() func2; } void noth(Sample smpl)() { smpl.func1(); // Error: expression __lambda1 is not a valid template value argument smpl.func2(); // Error: expression __lambda2 is not a valid template value argument } void main(){ enum s = Sample( {writeln("Hello world1");}, {writeln("Hello world2");} ); s.func1(); s.func2(); noth!(s)(); } ``` https://forum.dlang.org/thread/mggbomxhjpglltsih...@forum.dlang.org
Strange error
Could someone please explain what is wrong with this code? https://glot.io/snippets/fwxn2198kv ```d import std.stdio; struct Sample{ void function() func1; void function() func2; } void noth(Sample smpl)() { smpl.func1(); // Error: expression __lambda1 is not a valid template value argument smpl.func2(); // Error: expression __lambda2 is not a valid template value argument } void main(){ enum s = Sample( {writeln("Hello world1");}, {writeln("Hello world2");} ); s.func1(); s.func2(); noth!(s)(); } ```
Re: Static Array with negative index results in a strange error-message
On 4/23/18 11:09 AM, Dgame wrote: It's really fun playing around: char[int.max - 1] c; results in Internal error: dmd/backend/cgcod.c 634 with DMD 2.079. Guess I or somebody else should report this. Yes, this is an ICE (Internal compiler error). Those should ALWAYS be reported. -Steve
Re: Static Array with negative index results in a strange error-message
It's really fun playing around: char[int.max - 1] c; results in Internal error: dmd/backend/cgcod.c 634 with DMD 2.079. Guess I or somebody else should report this.
Re: Static Array with negative index results in a strange error-message
On Monday, 23 April 2018 at 13:48:07 UTC, Steven Schveighoffer wrote: On 4/23/18 9:32 AM, Dgame wrote: char[-1] c; results in Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fff size limit for static array Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message. Hm.. at least it's detected. I actually don't think the message is wrong: -1 is a valid size_t literal, and results in that number. if you did: enum size_t x = -1; char[x] c; You would get the same result, and I don't know how we would fix that. -Steve C's error message is error: 'c' declared as an array with a negative size char c[-1]; That is more understandable.
Re: Static Array with negative index results in a strange error-message
On 4/23/18 9:32 AM, Dgame wrote: char[-1] c; results in Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fff size limit for static array Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message. Hm.. at least it's detected. I actually don't think the message is wrong: -1 is a valid size_t literal, and results in that number. if you did: enum size_t x = -1; char[x] c; You would get the same result, and I don't know how we would fix that. -Steve
Static Array with negative index results in a strange error-message
char[-1] c; results in Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fff size limit for static array Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message.
Re: Strange error when compiling with dmd, not with ldc
On Wednesday, 29 November 2017 at 10:55:35 UTC, user1234 wrote: On Wednesday, 29 November 2017 at 06:18:09 UTC, Fra Mecca wrote: [...] You must also use a type constructor later, when a Configuration is declared: ``` immutable(Configuration) config; config.toString.writeln; // okay this time ``` What happens is that all the member functions have the `immutable` attribute, but the instance you declared was not itself `immutable`. actually this: ``` immutable struct Configuration { @property string toString(){return "";} } ``` is like: ``` struct Configuration { @property string toString() immutable {return "";} } ``` I would personally prefer the second form. Why ? Because the variable members will be set immutable anyway when an instance is declared. And about the DMD vs LDC thing, i thing that the difference can be simply explained by the fact that LDC uses a slightly older compiler front end version, meaning that after 1 or 2 updates, the same error would happen. Now i don't know which change in particular has been made recently in the front-end. Maybe the semantic of the leading qualifier when "immutable struct {}" is used but i would bet too much on that.
Re: Strange error when compiling with dmd, not with ldc
On Wednesday, 29 November 2017 at 06:18:09 UTC, Fra Mecca wrote: I have this struct: immutable struct Configuration { string title; string baseurl; string url; string email; string author; string parser; string target; string urlFormat; string urlFormatCmd; short port; string[] ignore; string[] extensions; @property string toString() { auto urlF = (urlFormatCmd ? "url_format_cmd: " ~ urlFormatCmd : "") ~ "\n"; return "title: "~ title ~ "\n" ~ "baseurl: " ~ baseurl ~ "\n" ~ "url: " ~ url ~ "\n" ~ "email: "~ email ~ "\n" ~ "author: " ~ author ~ "\n" ~ "parser: " ~ parser ~ "\n" ~ "target: " ~ target ~ "\n" ~ "url_format: " ~ urlFormat ~ "\n" ~ "ignore: " ~ to!string(ignore)[1 .. $ - 1] ~ "\n" ~ "extensions: " ~ to!string(extensions)[1 .. $ - 1] ~ "\n" ~ urlF; } } and this function: void show_config() { writef("%s", parse_config( exists("config.sdl") ? "config.sdl" : "").toString); } Whenever I compile with ldc2 I get no errors, while with dmd I get: source/configuration.d(105,27): Error: immutable method configuration.Configuration.toString is not callable using a mutable object What is the problem? You must also use a type constructor later, when a Configuration is declared: ``` immutable(Configuration) config; config.toString.writeln; // okay this time ``` What happens is that all the member functions have the `immutable` attribute, but the instance you declared was not itself `immutable`. actually this: ``` immutable struct Configuration { @property string toString(){return "";} } ``` is like: ``` struct Configuration { @property string toString() immutable {return "";} } ``` I would personally prefer the second form. Why ? Because the variable members will be set immutable anyway when an instance is declared.
Strange error when compiling with dmd, not with ldc
I have this struct: immutable struct Configuration { string title; string baseurl; string url; string email; string author; string parser; string target; string urlFormat; string urlFormatCmd; short port; string[] ignore; string[] extensions; @property string toString() { auto urlF = (urlFormatCmd ? "url_format_cmd: " ~ urlFormatCmd : "") ~ "\n"; return "title: "~ title ~ "\n" ~ "baseurl: " ~ baseurl ~ "\n" ~ "url: " ~ url ~ "\n" ~ "email: "~ email ~ "\n" ~ "author: " ~ author ~ "\n" ~ "parser: " ~ parser ~ "\n" ~ "target: " ~ target ~ "\n" ~ "url_format: " ~ urlFormat ~ "\n" ~ "ignore: " ~ to!string(ignore)[1 .. $ - 1] ~ "\n" ~ "extensions: " ~ to!string(extensions)[1 .. $ - 1] ~ "\n" ~ urlF; } } and this function: void show_config() { writef("%s", parse_config( exists("config.sdl") ? "config.sdl" : "").toString); } Whenever I compile with ldc2 I get no errors, while with dmd I get: source/configuration.d(105,27): Error: immutable method configuration.Configuration.toString is not callable using a mutable object What is the problem?
Re: Trying to pass lambda to function gives strange error
On Saturday, 11 June 2016 at 22:58:00 UTC, Incognito wrote: function foo (double x, double y, bool function(bar) callback) is not callable using argument types (double, double, bool function() pure nothrow @nogc @safe function(bar w) pure nothrow @nogc @safe) I've tried with passing a delegate. I am calling it like foo(0,0, (bar b) => { return true; }); It seems the only difference is all those attributes?!?! Surely I don't have to specify all that junk when creating a lambda? Nevermind. The => is the problem. D should definitely give a better warning message than that!
Trying to pass lambda to function gives strange error
function foo (double x, double y, bool function(bar) callback) is not callable using argument types (double, double, bool function() pure nothrow @nogc @safe function(bar w) pure nothrow @nogc @safe) I've tried with passing a delegate. I am calling it like foo(0,0, (bar b) => { return true; }); It seems the only difference is all those attributes?!?! Surely I don't have to specify all that junk when creating a lambda?
Re: alias overloading strange error
On Friday, 31 July 2015 at 11:09:39 UTC, anonymous wrote: Definitely a bug. Please file an issue at https://issues.dlang.org/. https://issues.dlang.org/show_bug.cgi?id=14858
alias overloading strange error
//Why expression 'foobar(1);' doesn't work? void foo()(){} void bar(int){} alias foobar = foo; alias foobar = bar; void main(){ .foobar(1); //OK foobar(1); //Error: overload alias 'foo' is not a variable }
Re: alias overloading strange error
On Friday, 31 July 2015 at 10:56:33 UTC, vitus wrote: //Why expression 'foobar(1);' doesn't work? void foo()(){} void bar(int){} alias foobar = foo; alias foobar = bar; void main(){ .foobar(1); //OK foobar(1); //Error: overload alias 'foo' is not a variable } foo is a template, while bar is a function. I would have thought the `.foobar(1)` should have failed too... Must be some strange lookup rules I don't know about (or a dmd bug). `alias foobar = foo!();` should make it work in both cases though.
Re: alias overloading strange error
On Friday, 31 July 2015 at 10:56:33 UTC, vitus wrote: //Why expression 'foobar(1);' doesn't work? void foo()(){} void bar(int){} alias foobar = foo; alias foobar = bar; void main(){ .foobar(1); //OK foobar(1); //Error: overload alias 'foo' is not a variable } It works when you switch the aliases around: void foo()(){} void bar(int){} alias foobar = bar; alias foobar = foo; void main(){ foobar(1); } Definitely a bug. Please file an issue at https://issues.dlang.org/.
Re: strange error with std.net.curl
On Sunday, 4 May 2014 at 16:40:08 UTC, Suliman wrote: I am trying to compile next code: import std.net.curl; import std.stdio; void main() { writeln(get(https://google.com/;)); } and got next error http://www.everfall.com/paste/id.php?y37dr6qmu54h this is related to verifying certificates. see http://forum.dlang.org/thread/mailman.357.1384163617.9546.digitalmar...@puremagic.com
strange error with std.net.curl
I am trying to compile next code: import std.net.curl; import std.stdio; void main() { writeln(get(https://google.com/;)); } and got next error http://www.everfall.com/paste/id.php?y37dr6qmu54h
Strange error
This code (http://dpaste.dzfl.pl/4c499303) causes strange error description: class Bar had semantic errors when compiling On win32 it causes AV: Error: class Bar had semantic errors when compiling Assertion failure: '0' on line 1215 in file 'glue.c'
Re: Strange error
Go to bugzilla.
Strange error
Hello guys ! I'm found strange error when compiling following code: http://dpaste.1azy.net/b40ce9a4 The error is: src\phobos\std\stdio.d(1872): Error: variable _param_1 used before set Problem exists only when using following options: -inline -O I'm using DMD 2.063.2 on Windows. Can anybody help with it ? Also i can't minimize the test-case.
Re: Strange error
On Thursday, 4 July 2013 at 08:34:24 UTC, Temtaime wrote: Hello guys ! I'm found strange error when compiling following code: http://dpaste.1azy.net/b40ce9a4 The error is: src\phobos\std\stdio.d(1872): Error: variable _param_1 used before set Problem exists only when using following options: -inline -O I'm using DMD 2.063.2 on Windows. Can anybody help with it ? Also i can't minimize the test-case. Looks like a bug related with size 0 matrices: It makes you declare an empty static array, which then does some conflicts, since the code to initialize it is optimized out. Reduced test case: struct S { int[0] a; void do_it() { foo(a); } } void foo(Args...)(Args args) { foreach(arg; args) if (arg.ptr == null) return; bar(args); } void bar(Args...)(Args args) { baz(args); } void baz(Args...)(Args args) { foreach(arg; args) if (arg.ptr == null) return; } void main() {} I've filed it: http://d.puremagic.com/issues/show_bug.cgi?id=10540 To workaround it, I'd suggest writing your code in such a way that you stop the recursion a 1, and not 0.
Re: Strange error when importing std.regex
On Wednesday, 12 June 2013 at 18:44:12 UTC, bearophile wrote: Dmitry Olshansky: There is no ambiguity, 1 is not a Regex object but it seems like template constraint in std.regex blows up. @Temtaime please file a bug on this. http://d.puremagic.com/issues/ std.algorithm.splitter(arr, 1); I think this bug already surfaced some time ago... Maybe it's already in Bugzilla. Bye, bearophile Right now I cannot see the original code in dpaste, but the issue would be a same bug with 8352. http://d.puremagic.com/issues/show_bug.cgi?id=8352 I have maintained a compiler fix for that, but unfortunately it is not yet merged. https://github.com/D-Programming-Language/dmd/pull/1660 Kenji Hara
Strange error when importing std.regex
Hello guys! http://dpaste.1azy.net/9c4c3eb8 http://dpaste.1azy.net/afd8d20b How i can avoid this?
Re: Strange error when importing std.regex
Temtaime: How i can avoid this? You have to qualify where the function comes from. One way to do it is to use: std.algorithm.splitter(arr, 1); Bye, bearophile
Re: Strange error when importing std.regex
Oh, thanks very much.
Re: Strange error when importing std.regex
12-Jun-2013 17:28, bearophile пишет: Temtaime: How i can avoid this? You have to qualify where the function comes from. One way to do it is to use: There is no ambiguity, 1 is not a Regex object but it seems like template constraint in std.regex blows up. @Temtaime please file a bug on this. http://d.puremagic.com/issues/ std.algorithm.splitter(arr, 1); Bye, bearophile -- Dmitry Olshansky
Re: Strange error when importing std.regex
Dmitry Olshansky: There is no ambiguity, 1 is not a Regex object but it seems like template constraint in std.regex blows up. @Temtaime please file a bug on this. http://d.puremagic.com/issues/ std.algorithm.splitter(arr, 1); I think this bug already surfaced some time ago... Maybe it's already in Bugzilla. Bye, bearophile