Commit graph

24 commits

Author SHA1 Message Date
Paul Backus
a504a5e7d6 Fix Issue 23182 - Can't assign struct with opAssign to SumType in CTFE
SumType.opAssign now avoids calling core.lifetime.move or
core.lifetime.forward during CTFE whenever possible.
2022-06-14 04:38:57 +00:00
João Lourenço
5e746a0490
test(sumtype): utilize D_Invariants conditional compilation
Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
2022-05-30 10:35:07 +01:00
João Lourenço
d39c4ea290
test(sumtype): add unittests when returning the matched value's reference
Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
2022-05-11 21:23:57 +01:00
João Lourenço
6069c44930
fix(sumtype): template canMatch does not account for ref when matching
The template `canMatch` does not account for `ref`.
The template `valueTypes` stores all types of the member values and uses SumTypes's `get` function, which returns a `ref`.
However, ref does not persist and the type is not sent to `canMatch` as a `ref`.
Because of this, when matching, `canMatch` will fail as it will test for a copy, and returning a reference of that value results in escaping it.

Fix Issue 23101

Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
2022-05-10 20:25:46 +01:00
Paul Backus
c6b4bd9638 [Refactor] Move toCtString to std.conv
Previously, it was duplicated in std.functional and std.sumtype.
2022-03-26 14:04:37 +00:00
Paul Backus
d9d104c9bc Fix issue 22901 - Can't construct inout SumType
The template constraint is needed to ensure that the inout constructor
overload is only considered when it is an exact match, without qualifier
conversions.

Without the constraint, a constructor call such as

    const(SumType!(int[]))([1, 2, 3])

...would be ambiguous, since it would match both the const constructor
overload and the inout constructor overload at the "match with qualifier
conversion" level.
2022-03-20 14:57:40 -04:00
canopyofstars
668d43c5df Fix 22851 - Add source reference to std.sumtype
Add `Source: $(PHOBOSSRC std/sumtype.d)` to `std.sumtype's` module documentation.
2022-03-06 03:34:35 +00:00
Paul Backus
a1f8c4c070 Revert "sumtype: work around issue 21975 in isSumType"
This reverts commit 2de68340ae.
2022-03-01 15:09:30 +00:00
Paul Backus
2de68340ae sumtype: work around issue 21975 in isSumType
isSumType!T now evaluates to true instead of false when T is a templated
struct type that implicitly converts to a SumType via alias this.
2022-02-27 23:15:28 +00:00
Paul Backus
5e3c4af308 sumtype: add example of memory corruption to docs
This makes it clearer why SumType.opAssign must sometimes be @system.
2022-02-23 18:30:07 +00:00
Paul Backus
5ca44b74a5 Fix Issue 22572 - Cannot define SumType over immutable struct with Nullable
Previously, SumType incorrectly assumed that all members of an
inout(SumType) must themselves be inout-qualified. However, this is not
the case when one of those member types is declared as immutable, since
the qualifier combination `immutable inout` collapses to just
`immutable`.

Attempting to copy an immutable member type as though it were inout
caused matching to fail in SumType's copy constructor, due to the
following (gagged) error:

  Error: `inout` on `return` means `inout` must be on a parameter as
  well for `pure nothrow @nogc @safe inout(Storage)(ref immutable(Value)
  value)`
2022-02-09 22:50:10 +00:00
wolframw
cab079a276 sumtype: remove redundant "See Also" in tryMatch documentation 2021-12-22 21:24:30 +00:00
Paul Backus
5ac515b52c Fix Issue 22117 - Can't store scope pointer in a SumType
Previously, the assignment of the local variable 'newStorage' to the
longer-lived member variable 'storage' caused scope inference to
(correctly) fail.

newStorage was necessary to work around issues 21229 and 22118. Since
those issues have been fixed, newStorage can be safely removed.
2021-08-23 21:52:40 -04:00
Paul Backus
f96f8046d9 Fix Issue 22225 - SumType: Some assignments should be able to execute in safe code 2021-08-19 23:07:12 +00:00
Paul Backus
32f32525bf Fix issue 22077 - std.sumtype support for copy constructors is incomplete
Previously, SumType would define the wrong set of constructors for types
whose copyability varies depending on their mutability--a situation that
was impossible with postblits, but is now possible with copy
constructors.
2021-08-12 03:23:11 +00:00
Dennis
1cb398ffcd
Disable non-@nogc unittest in -betterC (#8163) 2021-07-13 08:55:35 +08:00
berni44
b2019ebab0 Narrow imports of std.math in the rest of phobos. 2021-04-21 03:00:57 +02:00
Atila Neves
7407ce93cd Revert "Fix Issue 21731 - SumType should provide convenient access to the typ…" 2021-03-26 22:01:23 +01:00
The Dlang Bot
5dd4446c80
Merge pull request #7886 from pbackus/sumtype-type-index
Fix Issue 21731 - SumType should provide convenient access to the typ…
merged-on-behalf-of: Steven Schveighoffer <schveiguy@users.noreply.github.com>
2021-03-20 15:10:59 +01:00
Paul Backus
e1baa9b6a0 Reword documentation for SumType.typeIndex
The new wording describes the result without implying anything about the
implementation.
2021-03-20 00:19:28 -04:00
Paul Backus
50c7945236 Fix Issue 21731 - SumType should provide convenient access to the type index 2021-03-19 17:12:27 -04:00
berni44
6f2a0934a7 Adapt imports of std.format to new structure of std.format. 2021-03-19 13:22:00 +01:00
Paul Backus
56bc37c8e5 Fix Issue 21708 - SumType.opEquals gives confusing error message 2021-03-13 23:28:48 +01:00
Paul Backus
51a70ee267
Add sumtype to Phobos (#7702)
Add sumtype to Phobos
merged-on-behalf-of: unknown
2021-03-05 12:41:34 +01:00