[Issue 24030] New: A `lazy` parameter shouldn't be allowed to be "called" twice

2023-07-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24030

  Issue ID: 24030
   Summary: A `lazy` parameter shouldn't be allowed to be "called"
twice
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: qs.il.paperi...@gmail.com

It’s quite straightforward: The intended use for `lazy` is to defer evaluation;
everyone seeing this for the first time expects that. The fact that a function
taking a `lazy` parameter may evaluate the underlying delegate more than once
is surprising. Only once a programmer learns that there is a delegate
underlying, it makes some sense.

This is a breaking change, but there’s a simple transition path: Use a delegate
explicitly, and you’ll surprise nobody.

Checking that a `lazy` parameter is evaluated at most once only needs a very
limited form of control-flow analysis. In `@system` code, this could be ignored
and calling a `lazy` parameter more than once becomes Undefined Behavior.

If desired, on non-release builds, the only-call-once rule can be asserted by
introducing a hidden `bool` variable on the caller’s side:

```d
int f(lazy int);

1 + f(1);
```

is lowered to:

```d
int f(int delegate());

bool called; // unique name
1 + f({
assert(!called);
called = true;
return 1;
});
```

What about `lazy` `void` parameters?

They’re no different. You’re after the side-effect, but again, getting it more
than once will be surprising; use a delegate.

--


[Issue 24024] cannot pass class this to ref class

2023-07-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24024

kinke  changed:

   What|Removed |Added

 CC||ki...@gmx.net

--- Comment #1 from kinke  ---
This is the behavior I would expect - a class-ref `this` is special and not to
be mutated. What if `foo()` sets it to null?

--


[Issue 24025] Expressions contained in parentheses should not be assumed to be C casts

2023-07-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24025

Dlang Bot  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #3 from Dlang Bot  ---
dlang/dmd pull request #15377 "Fix Issue 24025 - Expressions contained in
parentheses should not be …" was merged into master:

- 9f782c456e31a4fad5027961d64c346d388f1b7e by Nick Treleaven:
  Fix Issue 24025 - Expressions contained in parentheses should not be assumed
to be C casts

  Allow `(identifier)` and `(BasicType)` when followed by a left parenthesis.
  These can be a function call or an implicit conversion - the latter may
  produce a semantic error (not a parse error).

https://github.com/dlang/dmd/pull/15377

--


[Issue 24029] ImportC: symbol name clash on statement expressions

2023-07-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24029

Dlang Bot  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #2 from Dlang Bot  ---
dlang/dmd pull request #15378 "fix Issue 24029 - ImportC: symbol name clash on
statement expressions" was merged into master:

- aa7024012d1d196dbf36b49f0e2982dcb01d247e by Walter Bright:
  fix Issue 24029 - ImportC: symbol name clash on statement expressions

https://github.com/dlang/dmd/pull/15378

--


[Issue 23966] [REG2.102] Cannot use traits(getAttributes) with overloaded template

2023-07-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=23966

Dlang Bot  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #5 from Dlang Bot  ---
dlang/dmd pull request #15353 "Fix Issue 23966 - [REG2.102] Cannot use
traits(getAttributes) with overloaded template" was merged into stable:

- bf2c04df822eee078ec0debb151c09d794f709c9 by RazvanN7:
  Fix Issue 23966 - [REG2.102] Cannot use traits(getAttributes) with overloaded
template

https://github.com/dlang/dmd/pull/15353

--