From 77d6794b26184feb9ea7a757cf0fb557badc0542 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 15:36:51 +0000 Subject: [PATCH] Tidy array validation flow Agent-Logs-Url: https://github.com/wesleyel/swiftui-math/sessions/56436444-e15b-4dd0-8a70-c87df1e3dc4e Co-authored-by: wesleyel <48174882+wesleyel@users.noreply.github.com> --- Sources/SwiftUIMath/Internal/Syntax/AtomFactory.swift | 2 +- Sources/SwiftUIMath/Internal/Syntax/Parser.swift | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftUIMath/Internal/Syntax/AtomFactory.swift b/Sources/SwiftUIMath/Internal/Syntax/AtomFactory.swift index 4c71b22..8314929 100644 --- a/Sources/SwiftUIMath/Internal/Syntax/AtomFactory.swift +++ b/Sources/SwiftUIMath/Internal/Syntax/AtomFactory.swift @@ -712,7 +712,7 @@ extension Math { return table } } else if env == "array" { - guard let columnAlignments, !columnAlignments.isEmpty else { + guard let columnAlignments else { let message = "array environment requires at least 1 column alignment" if error == nil { error = ParserError(code: .invalidEnvironment, message: message) diff --git a/Sources/SwiftUIMath/Internal/Syntax/Parser.swift b/Sources/SwiftUIMath/Internal/Syntax/Parser.swift index 12596a8..aa9cb1b 100644 --- a/Sources/SwiftUIMath/Internal/Syntax/Parser.swift +++ b/Sources/SwiftUIMath/Internal/Syntax/Parser.swift @@ -1332,18 +1332,22 @@ extension Math { } } - if self.error == nil && !foundClosingBrace { + if !foundClosingBrace { self.setError(.characterNotFound, message: "Missing } after array column format") } - if self.error == nil && columnAlignments.isEmpty { + if columnAlignments.isEmpty { self.setError( .invalidEnvironment, message: "array environment requires at least one column alignment specifier (l, c, or r)" ) } - return self.error == nil ? (columnAlignments, format) : (nil, nil) + if self.error != nil { + return (nil, nil) + } + + return (columnAlignments, format) } func assertNotSpace(_ ch: Character) {