From ff1bbfad5fb4bc74df965eee935b49862d959e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20R=C3=B6ssel?= Date: Sat, 15 Aug 2020 21:52:56 +0200 Subject: [PATCH] Rollback of null handling in RowAtom. --- src/WpfMath/Atoms/RowAtom.cs | 9 +++++---- src/WpfMath/Atoms/StyledAtom.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/WpfMath/Atoms/RowAtom.cs b/src/WpfMath/Atoms/RowAtom.cs index a4d8fb39..b7383415 100644 --- a/src/WpfMath/Atoms/RowAtom.cs +++ b/src/WpfMath/Atoms/RowAtom.cs @@ -34,12 +34,12 @@ static RowAtom() ligatureKernChangeSet.Set((int)TexAtomType.Punctuation, true); } - public RowAtom(SourceSpan? source, Atom baseAtom) + public RowAtom(SourceSpan? source, Atom? baseAtom) : this( source, baseAtom is RowAtom ? (IEnumerable) ((RowAtom) baseAtom).Elements - : new[] { baseAtom }) + : new[] { baseAtom! }) // Nullable: Seems to require some sort of non-null assertion to make the analyzer happy { } @@ -56,9 +56,10 @@ private RowAtom(SourceSpan? source, DummyAtom? previousAtom, ReadOnlyCollection< this.Elements = elements; } - internal RowAtom(SourceSpan? source, IEnumerable elements) + internal RowAtom(SourceSpan? source, IEnumerable elements) : base(source) => - this.Elements = elements.ToList().AsReadOnly(); + this.Elements = elements.Where(x => x != null).ToList().AsReadOnly()!; + // TODO[F]: Fix this with C# 8 migration: there shouldn't be nullable atoms in this collection public DummyAtom? PreviousAtom { get; } diff --git a/src/WpfMath/Atoms/StyledAtom.cs b/src/WpfMath/Atoms/StyledAtom.cs index 1481c014..878c42e1 100644 --- a/src/WpfMath/Atoms/StyledAtom.cs +++ b/src/WpfMath/Atoms/StyledAtom.cs @@ -9,7 +9,7 @@ internal class StyledAtom : Atom, IRow public StyledAtom(SourceSpan? source, Atom? atom, Brush? backgroundColor, Brush? foregroundColor) : base(source) { - this.RowAtom = new RowAtom(source, atom!); // Nullable TODO: This definitely needs null checking and is currently wrong + this.RowAtom = new RowAtom(source, atom); this.Background = backgroundColor; this.Foreground = foregroundColor; }