On Wednesday, 25 May 2022 at 05:56:28 UTC, Steven Schveighoffer
wrote:
It's a case where the compiler can't divine what you were
thinking when you wrote that code ;)
I see not in all cases but in mine. If the compiler sees the
function isn't callable without arguments and it is inside an
if
On 5/25/22 1:40 AM, frame wrote:
This would have been more visible if the compiler just says: "function
cannot be compared against null, only function pointer". That function
vs function pointer is too subtle.
It's a case where the compiler can't divine what you were thinking when
you wrot
On Wednesday, 25 May 2022 at 04:34:43 UTC, Steven Schveighoffer
wrote:
Well, you can possibly work around the type system, but I don't
know what the compiler thinks you have there.
This really bothers me and I put this test cases:
```d
static if (isSomeFunction!fun) pragma(msg,...)
static i
On 5/25/22 12:16 AM, frame wrote:
On Wednesday, 25 May 2022 at 03:41:17 UTC, Steven Schveighoffer wrote:
This is a compiler bug, at least I think so. Since the compiler is
misbehaving, it's not clear how to make it behave.
-Steve
Well, ok, it's not my top priority and dustmite seems to run
On Wednesday, 25 May 2022 at 03:41:17 UTC, Steven Schveighoffer
wrote:
This is a compiler bug, at least I think so. Since the compiler
is misbehaving, it's not clear how to make it behave.
-Steve
Well, ok, it's not my top priority and dustmite seems to run
better on Unix - which I need to
On 5/24/22 11:14 PM, frame wrote:
On Wednesday, 25 May 2022 at 02:42:26 UTC, Steven Schveighoffer wrote:
try:
pragma(msg, typeof(fun));
Outputs:
```
extern (C) void function(...)
```
OK, so it's a function pointer.
But the compiler would complain if I call it as a type? And how could i
On Wednesday, 25 May 2022 at 02:42:26 UTC, Steven Schveighoffer
wrote:
Just to be pedantic, you tried that call in the *exact place*
the assert is failing to compile? D can be weird/surprising
about name lookups.
Yes, of course ;-)
try:
pragma(msg, typeof(fun));
Outputs:
```
extern (C)
On 5/24/22 10:06 PM, frame wrote:
Sorry, this was not affront, it was meant as my POV that you may have
problems to get my problem because I have (as usually) forgot to make
this more visible that some code was truncated.
OK, sorry to read into that ;)
I tried your suggestion, as replied to
On Tuesday, 24 May 2022 at 22:18:44 UTC, Adam D Ruppe wrote:
There's a big difference between a function and a function
pointer.
Could you please clarify in this context?
`Fun` is basically generated by code like that:
```d
extern (Windows) void* GetProcAddress(void*, const char*);
auto fn =
On Wednesday, 25 May 2022 at 01:23:56 UTC, Steven Schveighoffer
wrote:
"of course" I have no idea what your real code looks like,
unless you post the real code.
While I get the point of trying to slim down the example to
something postable, a very common problem with this kind of
self-trimm
On 5/24/22 6:54 PM, Andrey Zherikov wrote:
On Tuesday, 24 May 2022 at 22:51:50 UTC, Adam Ruppe wrote:
On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote:
return S(s);
return S(s.dup);
The variadic lives in a temporary array that expires at the end of the
function. So copyin
On 5/24/22 6:10 PM, frame wrote:
On Tuesday, 24 May 2022 at 19:09:52 UTC, Steven Schveighoffer wrote:
This doesn't seem valid for module-level code, assert is an
instruction, not a declaration.
...
Try `std.traits.fullyQualifiedName!fun` to see where it's coming from.
expected 5 got 0 suggest
On Tuesday, 24 May 2022 at 22:51:50 UTC, Adam Ruppe wrote:
On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote:
return S(s);
return S(s.dup);
The variadic lives in a temporary array that expires at the end
of the function. So copying it out to the GC lets it live on.
Yo
On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote:
return S(s);
return S(s.dup);
The variadic lives in a temporary array that expires at the end
of the function. So copying it out to the GC lets it live on.
Your code was wrong on 2.099 too, but the compiler didn't tell
How to fix this?
```d
struct S
{
string[] s;
}
auto foo(string[] s...) // Error: typesafe variadic function
parameter `s` of type `string[]` cannot be marked `return`
{
return S(s);
}
void main()
{
import std.stdio: writeln;
writeln(foo("Hello D"));
}
```
Th
On Tuesday, 24 May 2022 at 22:10:21 UTC, frame wrote:
To also anwser to Adam: no, this symbol is unique. The first
line of the error says:
```
Error: function `a.fun(string param)` is not callable using
argument types `()`.
```
There's a big difference between a function and a function
poi
Just looking at the error, are 2.098.1 & 2.100 , 100% compatible ?
On Tuesday, 24 May 2022 at 19:09:52 UTC, Steven Schveighoffer
wrote:
This doesn't seem valid for module-level code, assert is an
instruction, not a declaration.
...
Try `std.traits.fullyQualifiedName!fun` to see where it's
coming from.
expected 5 got 0 suggests it is finding some other fun,
On Tuesday, 24 May 2022 at 21:05:00 UTC, Steven Schveighoffer
wrote:
[snip]
```d
// e.g.
foo(int x)
in (x >= 0)
{
return foo(uint(x));
}
```
And remove those useless `in` conditions on the unsigned
versions, an unsigned variable is always >= 0.
-Steve
Thanks. That makes perfect sense. I
On 5/24/22 4:46 PM, jmh530 wrote:
In the code below, `x` and `y` are implicitly converted to `uint` and
`ushort` before the function preconditions are run.
Is there any way to change this behavior? It feels unintuitive and I
can't find in the spec where it says when the conversions in this cas
In the code below, `x` and `y` are implicitly converted to `uint`
and `ushort` before the function preconditions are run.
Is there any way to change this behavior? It feels unintuitive
and I can't find in the spec where it says when the conversions
in this case occur, but it clearly happens be
On Tuesday, 24 May 2022 at 18:54:33 UTC, frame wrote:
Usually that works fine as shown in module A but for some
reason not in module B.
Do you have some other definition of fun somewhere?
On 5/24/22 3:09 PM, Steven Schveighoffer wrote:
assert is an instruction, not a declaration.
errr it's a *statement*, not a declaration.
-Steve
On 5/24/22 2:54 PM, frame wrote:
I have a function slot that may be loaded via a shared library.
I want to check if that function has an address but compiler (DMD 2.100,
Windows) instead tries to invocate the function?
```d
// --- module a:
alias F = extern (C) void function(string param);
F f
I have a function slot that may be loaded via a shared library.
I want to check if that function has an address but compiler (DMD
2.100, Windows) instead tries to invocate the function?
```d
// --- module a:
alias F = extern (C) void function(string param);
F fun = someLibLoad!F("name");
asser
On Tuesday, 24 May 2022 at 14:11:57 UTC, Steven Schveighoffer
wrote:
Note it has no idea what the real object type is at this point,
just that it is an Object (which does not have a @nogc
destructor).
It actually has nothing to do with Object. It doesn't have a
destructor at all, so there's n
On 5/23/22 10:29 PM, cc wrote:
```d
import core.memory;
import core.stdc.stdlib : malloc, free;
import core.lifetime : emplace;
T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) {
enum size = __traits(classInstanceSize, T);
void* mem = malloc(size);
scope(failure
27 matches
Mail list logo