diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift b/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift index cfbe8b615b..21361ffa98 100644 --- a/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift +++ b/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift @@ -168,8 +168,8 @@ public func ==(lhs: ATNConfig, rhs: ATNConfig) -> Bool { return true } - if (lhs is LexerATNConfig) && (rhs is LexerATNConfig) { - return (lhs as! LexerATNConfig) == (rhs as! LexerATNConfig) + if let l = lhs as? LexerATNConfig, let r = rhs as? LexerATNConfig { + return l == r } @@ -185,19 +185,7 @@ public func ==(lhs: ATNConfig, rhs: ATNConfig) -> Bool { return false } - var contextCompare = false - - if lhs.context == nil && rhs.context == nil { - contextCompare = true - } else if lhs.context == nil && rhs.context != nil { - contextCompare = false - } else if lhs.context != nil && rhs.context == nil { - contextCompare = false - } else { - contextCompare = (lhs.context! == rhs.context!) - } - - if !contextCompare { + if lhs.context != rhs.context { return false } diff --git a/runtime/Swift/Sources/Antlr4/atn/LexerATNConfig.swift b/runtime/Swift/Sources/Antlr4/atn/LexerATNConfig.swift index 1c4a0bb13f..38e55dc5e6 100644 --- a/runtime/Swift/Sources/Antlr4/atn/LexerATNConfig.swift +++ b/runtime/Swift/Sources/Antlr4/atn/LexerATNConfig.swift @@ -108,30 +108,11 @@ public func ==(lhs: LexerATNConfig, rhs: LexerATNConfig) -> Bool { return false } - if lhs.getLexerActionExecutor() == nil && rhs.getLexerActionExecutor() != nil { + if lhs.getLexerActionExecutor() != rhs.getLexerActionExecutor() { return false - } else if lhs.getLexerActionExecutor() != nil && rhs.getLexerActionExecutor() == nil { - return false - } else if lhs.getLexerActionExecutor() == nil && rhs.getLexerActionExecutor() == nil { - - } else if !(lhs.getLexerActionExecutor()! == rhs.getLexerActionExecutor()!) { - return false - } - - - var contextCompare = false - - if lhs.context == nil && rhs.context == nil { - contextCompare = true - } else if lhs.context == nil && rhs.context != nil { - contextCompare = false - } else if lhs.context != nil && rhs.context == nil { - contextCompare = false - } else { - contextCompare = (lhs.context! == rhs.context!) } - if !contextCompare{ + if lhs.context != rhs.context { return false } diff --git a/runtime/Swift/Sources/Antlr4/atn/SingletonPredictionContext.swift b/runtime/Swift/Sources/Antlr4/atn/SingletonPredictionContext.swift index 460740fee5..f711131272 100644 --- a/runtime/Swift/Sources/Antlr4/atn/SingletonPredictionContext.swift +++ b/runtime/Swift/Sources/Antlr4/atn/SingletonPredictionContext.swift @@ -71,16 +71,8 @@ public func ==(lhs: SingletonPredictionContext, rhs: SingletonPredictionContext) if lhs.returnState != rhs.returnState { return false } - var parentCompare = false - if (lhs.parent == nil) && (rhs.parent == nil) { - parentCompare = true - } else if lhs.parent == nil || rhs.parent == nil { - parentCompare = false - } else { - parentCompare = (lhs.parent! == rhs.parent!) - } - return parentCompare + return lhs.parent == rhs.parent } diff --git a/runtime/Swift/Sources/Antlr4/tree/pattern/Chunk.swift b/runtime/Swift/Sources/Antlr4/tree/pattern/Chunk.swift index 55c52aa798..c1ec8ca8ba 100644 --- a/runtime/Swift/Sources/Antlr4/tree/pattern/Chunk.swift +++ b/runtime/Swift/Sources/Antlr4/tree/pattern/Chunk.swift @@ -23,6 +23,6 @@ public class Chunk: Equatable { } public func isEqual(_ other: Chunk) -> Bool { - return false + return self === other } }