Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ read first.
| loud | the target frameworks | `net7.0;netstandard2.0` | `netstandard2.0;net8.0;net10.0` |
| **silent** | `abs(x) = c` for a negative `c` | a set of non-solutions | the empty set |
| loud | implicit `List<Entity>` to `Entity` | made a `FiniteSet`, and made three `params` overloads uncallable | removed |
| loud | implicit `Entity[]` to `Entity` | made a `FiniteSet`, discarding order and repeats | removed |
| **silent** | a `MathS.Settings` scope across an `await`, or inside a task | lost, or somebody else's | follows the call |

---
Expand Down Expand Up @@ -101,12 +102,12 @@ the built assemblies: present in `net8.0` and `net10.0`, absent from `netstandar

## Types and members

### The implicit conversion from `List<Entity>` is removed
### The implicit conversions from a collection are removed

`Entity` had two implicit conversions from a collection, both building a `FiniteSet`:

```csharp
public static implicit operator Entity(Entity[] elements);
public static implicit operator Entity(Entity[] elements); // removed
public static implicit operator Entity(List<Entity> elements); // removed
```

Expand Down Expand Up @@ -144,12 +145,24 @@ Write one of these instead:
```csharp
Entity set = new FiniteSet(new List<Entity> { 1, 2, 3 });
Entity set = new List<Entity> { 1, 2, 3 }.ToSet();
Entity set = new Entity[] { 1, 2, 3 }; // the array conversion is unchanged
```

The `Entity[]` conversion is kept: an array argument binds to the `params` overload in its normal
form by an identity conversion, which beats the alternatives outright, so it never produced the
ambiguity.
**The conversion from `Entity[]` is gone as well.** It was kept at first, on the narrow
ground that it never produced the ambiguity — an array binds to the `params` overload in its
normal form by an identity conversion, which wins outright. That was true and beside the
point. An array carries an order and can repeat an element; a set has neither, so the
conversion silently discarded part of what it was handed, and an implicit conversion that
loses information is the wrong shape regardless of which overloads it happens to break.
Set types are built explicitly nearly everywhere for this reason.

```csharp
Entity set = new Entity[] { 1, 2, 3 }; // no longer compiles either
Entity set = new FiniteSet(1, 2, 3); // say it
Entity set = new Entity[] { 1, 2, 3 }.ToSet();
```

Only one place in the whole repository relied on it, which was the test pinning it.

### A settings scope belongs to the call, not to the thread

`MathS.Settings` values were held in `[ThreadStatic]` fields — fourteen of them. A scope
Expand Down
1 change: 0 additions & 1 deletion Sources/AngouriMath/Core/Entity/Omni/Entity.Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public bool Contains(Entity entity)
#pragma warning disable CS1591
public static implicit operator Entity(Domain domain) => Set.SpecialSet.Create(domain);
public static implicit operator Entity((Entity left, Entity right) interval) => new Interval(interval.left, true, interval.right, true);
public static implicit operator Entity(Entity[] elements) => new FiniteSet(elements);
#pragma warning restore CS1591

}
Expand Down
18 changes: 13 additions & 5 deletions Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using AngouriMath;
using AngouriMath.Core;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Common
Expand All @@ -29,7 +30,7 @@
{
var solutions = new EquationSystem(Equations).Solve("x", "y");
Assert.NotNull(solutions);
Assert.Equal(1, solutions.RowCount);

Check warning on line 33 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 33 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 33 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

Dereference of a possibly null reference.

Check warning on line 33 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

Dereference of a possibly null reference.

Check warning on line 33 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Dereference of a possibly null reference.
Assert.Equal(2, solutions.ColumnCount);
}

Expand All @@ -38,7 +39,7 @@
{
var solutions = MathS.Equations(Equations).Solve("x", "y");
Assert.NotNull(solutions);
Assert.Equal(1, solutions.RowCount);

Check warning on line 42 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 42 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 42 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

Dereference of a possibly null reference.

Check warning on line 42 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

Dereference of a possibly null reference.

Check warning on line 42 in Sources/Tests/UnitTests/Common/ListArgumentOverloadTest.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Dereference of a possibly null reference.
}

[Fact]
Expand All @@ -59,14 +60,21 @@
}

/// <summary>
/// The conversion from an array is deliberately kept, so an array in an
/// <c>Entity</c> position is still a set.
/// An array in an <c>Entity</c> position is no longer a set. Both conversions are
/// gone: an array carries an order and repeats, a set has neither, so the conversion
/// silently discarded part of what it was handed — and it is the one that made the
/// overloads above ambiguous in the first place. Building a set says so instead.
/// </summary>
/// <remarks>
/// This compiling is what says the conversion has not come back; the assertion is
/// only that the explicit forms mean what they used to.
/// </remarks>
[Fact]
public void ArrayStillConvertsToASet()
public void AnArrayIsBuiltIntoASetExplicitly()
{
Entity set = new Entity[] { 1, 2, 3 };
Assert.Equal(new Entity.Set.FiniteSet(1, 2, 3), set);
var elements = new Entity[] { 1, 2, 3 };
Assert.Equal(new Entity.Set.FiniteSet(1, 2, 3), new Entity.Set.FiniteSet(elements));
Assert.Equal(new Entity.Set.FiniteSet(1, 2, 3), elements.ToSet());
}
}
}
1 change: 0 additions & 1 deletion Sources/Tests/UnitTests/Common/PublicApi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,6 @@ AngouriMath.Entity.op_ExclusiveOr(AngouriMath.Entity, AngouriMath.Entity) : Ango
AngouriMath.Entity.op_GreaterThan(AngouriMath.Entity, AngouriMath.Entity) : AngouriMath.Entity
AngouriMath.Entity.op_GreaterThanOrEqual(AngouriMath.Entity, AngouriMath.Entity) : AngouriMath.Entity
AngouriMath.Entity.op_Implicit(AngouriMath.Core.Domain) : AngouriMath.Entity
AngouriMath.Entity.op_Implicit(AngouriMath.Entity[]) : AngouriMath.Entity
AngouriMath.Entity.op_Implicit(PeterO.Numbers.EDecimal) : AngouriMath.Entity
AngouriMath.Entity.op_Implicit(PeterO.Numbers.EInteger) : AngouriMath.Entity
AngouriMath.Entity.op_Implicit(PeterO.Numbers.ERational) : AngouriMath.Entity
Expand Down
Loading