Re: How to do reflection on alias symbols

2023-11-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 16, 2023 6:04:43 PM MST Jonathan M Davis via 
Digitalmars-d-learn wrote:
> I would suggest that you open up a bug report for it -
> https://issues.dlang.org - and certainly, there's a good argument that what
> you're seeing here is a bug. I fully expect that what you're trying do just
> wasn't properly considered previously and thus was not dealt with properly
> when the other bugs for visibility attributes on aliases were fixed however
> many years ago that was now. I very much doubt that what you're seeing is
> the intended behavior - or at least I fully expect that if Walter or one of
> the other compiler devs sees the issue, they will agree that what you're
> trying to do should work.

Actually, it looks like there's already an old bug report on the issue:

https://issues.dlang.org/show_bug.cgi?id=12363

So, it has been reported, but it looks it's one of those that's gone under
the radar.

- Jonathan M Davis





Re: How to do reflection on alias symbols

2023-11-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 16, 2023 3:03:25 AM MST Arafel via Digitalmars-d-learn 
wrote:
> Hi all,
>
> Please consider the following currently non-working code:
>
> ```d
> struct bar {
>  public alias pubInt = int;
>  private alias privInt = int;
> }
>
> static foreach(member ; __traits(allMembers, bar)) {
>  // Error: argument `int` has no visibility
>  pragma(msg, __traits(getVisibility, __traits(getMember, bar, member)));
> }
> ```
>
> Is there any way to get the visibility, or more generically to reflect
> on an alias member as itself and not as the symbol pointed to without
> resorting to nasty __trait(compiles,...) tricks that fail more often
> than not?

Someone may be able to give you some advice on how to better deal with this
problem, but in general, aliases don't really exist as far as the compiler
is concerned. They get translated to the original type and handled that way
rather than treated as a separate type that translates to another type. They
exist enough that you can do stuff like give them different visibility
attributes for the original symbol, but that pretty much just affects
whether you can use the alias, and then it gets replaced with the real thing
immediately. As it is, IIRC, it was previously the case that there were bugs
where visibility attributes did not affect aliases properly, so it's not at
all surprising if there isn't a good way to access the visibility attribute
of the alias itself.

I would suggest that you open up a bug report for it -
https://issues.dlang.org - and certainly, there's a good argument that what
you're seeing here is a bug. I fully expect that what you're trying do just
wasn't properly considered previously and thus was not dealt with properly
when the other bugs for visibility attributes on aliases were fixed however
many years ago that was now. I very much doubt that what you're seeing is
the intended behavior - or at least I fully expect that if Walter or one of
the other compiler devs sees the issue, they will agree that what you're
trying to do should work.

- Jonathan M Davis





Re: Struct copy constructor with inout

2023-11-16 Thread Nick Treleaven via Digitalmars-d-learn

On Tuesday, 14 November 2023 at 13:58:17 UTC, Paul Backus wrote:
On Tuesday, 14 November 2023 at 13:41:32 UTC, Steven 
Schveighoffer wrote:

```
Error: copy constructor `testinoutctor.S1.this(ref const(S1) 
s) const` is not callable using argument types `(const(S1))`

```

I'm not sure what this means. There shouldn't be a copy being 
made here, as the thing is already const. I don't understand 
this error, and it looks like a bug to me.


The error is saying that the copy constructor expects a `const` 
`this` argument, but you're passing a mutable `this` argument.


Thanks for explaining, it's a confusing error.

The error when the constructor is changed to be immutable is:
```
Error: `immutable` method `immutable_ctor.S1.this` is not 
callable using a mutable object

```
(I've made a fix to say constructor instead of method for that.)
Now I've made a fix to produce a similar error for const:
https://issues.dlang.org/show_bug.cgi?id=24248


How to do reflection on alias symbols

2023-11-16 Thread Arafel via Digitalmars-d-learn

Hi all,

Please consider the following currently non-working code:

```d
struct bar {
public alias pubInt = int;
private alias privInt = int;
}

static foreach(member ; __traits(allMembers, bar)) {
// Error: argument `int` has no visibility
pragma(msg, __traits(getVisibility, __traits(getMember, bar, member)));
}
```

Is there any way to get the visibility, or more generically to reflect 
on an alias member as itself and not as the symbol pointed to without 
resorting to nasty __trait(compiles,...) tricks that fail more often 
than not?