ronantakizawa/codereview-bench huggingface dataset:
Repository: ClickHouse/ClickHouse
File: tests/queries/0_stateless/04003_array_join_in_filter_outer_to_inner_join.sql (SQL)

Code before:
-- Regression: segfault in executeActionForPartialResult when filter expression contains arrayJoin
-- and the convertOuterJoinToInnerJoin optimization tries to evaluate the filter with partial (null) arguments.
SELECT DISTINCT
    2,
    1048575
FROM numbers(1) AS l,
    numbers(2, isZeroOrNull(assumeNotNull(1))) AS r
ANY INNER JOIN r AS alias37 ON equals(alias37.number, r.number)
RIGHT JOIN l AS alias44 ON equals(alias44.number, alias37.number)
ANY INNER JOIN alias44 AS alias48 ON equals(alias48.number, r.number)
ANY RIGHT JOIN r AS alias52 ON equals(alias52.number, alias37.number)
WHERE equals(isNull(toLowCardinality(toUInt128(2))), arrayJoin([*, 13, 13, 13, toNullable(13), 13]))
GROUP BY
    materialize(1),
    isNull(toUInt128(2)),
    and(and(1048575, isZeroOrNull(1), isNullable(isNull(1))), materialize(13), isNull(toUInt256(materialize(2))), *, and(*, and(1, nan, isNull(isNull(1)), isZeroOrNull(1), 1048575), 13))
WITH CUBE;


Review comment (suggestion):
```suggestion
-- and the convertOuterJoinToInnerJoin optimization tries to evaluate the filter with partial (null) arguments.

SET enable_analyzer = 1;
```

Code after:
-- Regression: segfault in executeActionForPartialResult when filter expression contains arrayJoin
-- and the convertOuterJoinToInnerJoin optimization tries to evaluate the filter with partial (null) arguments.

SET enable_analyzer = 1;
SELECT DISTINCT
    2,
    1048575
FROM numbers(1) AS l,
    numbers(2, isZeroOrNull(assumeNotNull(1))) AS r
ANY INNER JOIN r AS alias37 ON equals(alias37.number, r.number)
RIGHT JOIN l AS alias44 ON equals(alias44.number, alias37.number)
ANY INNER JOIN alias44 AS alias48 ON equals(alias48.number, r.number)
ANY RIGHT JOIN r AS alias52 ON equals(alias52.number, alias37.number)
WHERE equals(isNull(toLowCardinality(toUInt128(2))), arrayJoin([*, 13, 13, 13, toNullable(13), 13]))
GROUP BY
    materialize(1),
    isNull(toUInt128(2)),
    and(and(1048575, isZeroOrNull(1), isNullable(isNull(1))), materialize(13), isNull(toUInt256(materialize(2))), *, and(*, and(1, nan, isNull(isNull(1)), isZeroOrNull(1), 1048575), 13))
WITH CUBE;
Repository: CodeEditApp/CodeEdit
File: CodeEditModules/Modules/AppPreferences/src/Sections/AccountsPreferences/Accounts/AccountListItem.swift (Swift)

Code before:
//
//  AccountListItem.swift
//  
//
//  Created by Nanshi Li on 2022/04/01.
//

import SwiftUI

struct AccountListItem: View {

    var gitClientName: String

    var body: some View {
        HStack {
            Image("vault.fill")
                .resizable()
                .frame(width: 28.0, height: 28.0)
            Text(gitClientName)
                .font(.system(size: 12))
        }
    }
}


Review comment (suggestion):
Please update to use the new `CodeEditSymbols` package. 

Reference:
* #472 
* https://github.com/CodeEditApp/CodeEditSymbols

Code after:
//
//  AccountListItem.swift
//  
//
//  Created by Nanshi Li on 2022/04/01.
//

import SwiftUI
import CodeEditSymbols

struct AccountListItem: View {

    var gitClientName: String

    var body: some View {
        HStack {
            Image(symbol: "vault.fill")
                .resizable()
                .frame(width: 28.0, height: 28.0)
            Text(gitClientName)
                .font(.system(size: 12))
        }
    }
}
Repository: CodeEditApp/CodeEdit
File: CodeEditModules/Modules/AppPreferences/src/Sections/AccountsPreferences/Accounts/Login/GitAccountItem.swift (Swift)

Code before:
//
//  GitAccountItem.swift
//  
//
//  Created by Nanshi Li on 2022/04/01.
//

import SwiftUI

struct GitAccountItem: View {

    @Binding
    var sourceControlAccount: SourceControlAccounts

    var body: some View {
        HStack {
            Image("vault.fill")
                .resizable()
                .frame(width: 24.0, height: 24.0)

            VStack(alignment: .leading) {
                Text(sourceControlAccount.gitProvider)
                    .font(.system(size: 12))
                Text(sourceControlAccount.gitProviderLink)
                    .font(.system(size: 10))
            }
        }
    }
}


Review comment (suggestion):
Please update to use the new `CodeEditSymbols` package. 

Reference:
* #472 
* https://github.com/CodeEditApp/CodeEditSymbols

Code after:
//
//  GitAccountItem.swift
//  
//
//  Created by Nanshi Li on 2022/04/01.
//

import SwiftUI
import CodeEditSymbols

struct GitAccountItem: View {

    @Binding
    var sourceControlAccount: SourceControlAccounts

    var body: some View {
        HStack {
            Image(symbol: "vault.fill")
                .resizable()
                .frame(width: 24.0, height: 24.0)

            VStack(alignment: .leading) {
                Text(sourceControlAccount.gitProvider)
                    .font(.system(size: 12))
                Text(sourceControlAccount.gitProviderLink)
                    .font(.system(size: 10))
            }
        }
    }
}
Repository: CodeEditApp/CodeEdit
File: CodeEditModules/Modules/CodeEditUI/src/PressActionsModifier.swift (Swift)

Code before:
//
//  Created by Gabriel Theodoropoulos on 1/11/20.
//

import SwiftUI

struct PressActions: ViewModifier {
    var onPress: () -> Void
    var onRelease: () -> Void
    func body(content: Content) -> some View {
        content
            .simultaneousGesture(
                DragGesture(minimumDistance: 0)
                    .onChanged({ _ in
                        onPress()
                    })
                    .onEnded({ _ in
                        onRelease()
                    })
            )
    }
}

extension View {
    func pressAction(onPress: @escaping (() -> Void), onRelease: @escaping (() -> Void)) -> some View {
        modifier(PressActions(onPress: {
            onPress()
        }, onRelease: {
            onRelease()
        }))
    }
}


Review comment (suggestion):
```swift
public struct PressActions: ViewModifier {
     private var onPress: () -> Void
     private var onRelease: () -> Void

     public init(onPress: @escaping () -> Void, 
                 onRelease: @escaping () -> Void) {
         self.onPress = onPress
         self.onRelease = onRelease
     }

     public func body(content: Content) -> some View {
         content
             .simultaneousGesture(
                 DragGesture(minimumDistance: 0)
                     .onChanged({ _ in
                         onPress()
                     })
                     .onEnded({ _ in
                         onRelease()
                     })
             )
     }
 }
```

Code after:
//
//  Created by Gabriel Theodoropoulos on 1/11/20.
//

import SwiftUI

public struct PressActions: ViewModifier {
     var onPress: () -> Void
     var onRelease: () -> Void
     public init(onPress: @escaping () -> Void, onRelease: @escaping () -> Void) {
         self.onPress = onPress
         self.onRelease = onRelease
     }
     public func body(content: Content) -> some View {
         content
             .simultaneousGesture(
                 DragGesture(minimumDistance: 0)
                     .onChanged({ _ in
                         onPress()
                     })
                     .onEnded({ _ in
                         onRelease()
                     })
             )
     }
}

public extension View {
    func pressAction(onPress: @escaping (() -> Void), onRelease: @escaping (() -> Void)) -> some View {
        modifier(PressActions(onPress: {
            onPress()
        }, onRelease: {
            onRelease()
        }))
    }
}
Repository: CodeEditApp/CodeEdit
File: CodeEdit/NavigatorSidebar/FindNavigator/FindNavigatorSearchBar.swift (Swift)

Code before:
//
//  SearchBar.swift
//  CodeEdit
//
//  Created by Ziyuan Zhao on 2022/3/21.
//

import SwiftUI
import CodeEditUI

struct FindNavigatorSearchBar: View {
    @ObservedObject
    private var state: WorkspaceDocument.SearchState

    @FocusState
    private var focusState: Bool

    private let title: String

    @Binding
    private var text: String

    init(state: WorkspaceDocument.SearchState,
         title: String,
         text: Binding<String>) {
        self.state = state
        self.title = title
        self._text = text
    }

    var body: some View {
        HStack {
            Image(systemName: "magnifyingglass")
                .foregroundColor(Color(nsColor: .secondaryLabelColor))
            textField
            if !text.isEmpty { clearButton }
        }
        .padding(.horizontal, 5)
        .padding(.vertical, 3)
        .background(focusState ?
                    EffectView(.contentBackground) :

Review comment (suggestion):
since this is a `Bool` rename it to something like `isFocused` so that it's clear in which occasion this is `true` or `false`.

Example:

```swift
.background(focusState ? // <- here it is not clear
   EffectView(.contentBackground) :
   EffectView(.underPageBackground, blendingMode: .withinWindow)
)

.background(isFocused ? // <- here it is clear
   EffectView(.contentBackground) :
   EffectView(.underPageBackground, blendingMode: .withinWindow)
)
```

Source: [Swift API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/)
> Uses of Boolean methods and properties should read as assertions about the receiver when the use is nonmutating, e.g. x.isEmpty, line1.intersects(line2).

Code after:
//
//  SearchBar.swift
//  CodeEdit
//
//  Created by Ziyuan Zhao on 2022/3/21.
//

import SwiftUI
import CodeEditUI

struct FindNavigatorSearchBar: View {
    @Environment(\.colorScheme)
    var colorScheme

    @ObservedObject
    private var state: WorkspaceDocument.SearchState

    @FocusState
    private var isFocused: Bool

    private let title: String

    @Binding
    private var text: String

    @Environment(\.controlActiveState)
    private var controlActive

    @ViewBuilder
    public func selectionBackground(
        _ isFocused: Bool = false
    ) -> some View {
        if self.controlActive != .inactive {
            if isFocused {
                if colorScheme == .light {
                    Color.white
                } else {
                    Color(hex: 0x1e1e1e)
                }
            } else {
                if colorScheme == .light {
Repository: CodeEditApp/CodeEdit
File: CodeEdit/NavigatorSidebar/FindNavigator/FindNavigatorSearchBar.swift (Swift)

Code before:
//
//  SearchBar.swift
//  CodeEdit
//
//  Created by Ziyuan Zhao on 2022/3/21.
//

import SwiftUI
import CodeEditUI

extension Color {
    init(hex: Int, opacity: Double = 1.0) {
        let red = Double((hex & 0xff0000) >> 16) / 255.0
        let green = Double((hex & 0xff00) >> 8) / 255.0
        let blue = Double((hex & 0xff) >> 0) / 255.0
        self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity)
    }
}

struct FindNavigatorSearchBar: View {
    @Environment(\.colorScheme)
    var colorScheme

    @ObservedObject
    private var state: WorkspaceDocument.SearchState

    @FocusState
    private var isFocused: Bool

    private let title: String

    @Binding
    private var text: String

    @Environment(\.controlActiveState)
    private var controlActive

    @ViewBuilder
    public func selectionBackground(
        _ isFocused: Bool = false
    ) -> some View {
        if self.controlActive != .inactive {
            if isFocused {

Review comment (suggestion):
Please extend the already available extensions in `CodeEditUtils/Extensions/Color+HEX.swift` to minimize code duplication.

Code after:
//
//  SearchBar.swift
//  CodeEdit
//
//  Created by Ziyuan Zhao on 2022/3/21.
//

import SwiftUI
import CodeEditUI

struct FindNavigatorSearchBar: View {
    @Environment(\.colorScheme)
    var colorScheme

    @ObservedObject
    private var state: WorkspaceDocument.SearchState

    @FocusState
    private var isFocused: Bool

    private let title: String

    @Binding
    private var text: String

    @Environment(\.controlActiveState)
    private var controlActive

    @ViewBuilder
    public func selectionBackground(
        _ isFocused: Bool = false
    ) -> some View {
        if self.controlActive != .inactive {
            if isFocused {
                if colorScheme == .light {
                    Color.white
                } else {
                    Color(hex: 0x1e1e1e)
                }
            } else {
                if colorScheme == .light {
                    Color.black.opacity(0.06)
                } else {
Repository: CodeEditApp/CodeEdit
File: CodeEditModules/Modules/StatusBar/src/Model/StatusBarTabType.swift (Swift)

Code before:
//
//  StatusBarTabType.swift
//  CodeEditModules/StatusBar
//
//  Created by Lukas Pistrol on 11.05.22.
//

import Foundation

/// A collection of types describing possible tabs in the Status Bar.
public enum StatusBarTabType: String, CaseIterable, Identifiable {
    case terminal
    case debugger
    case output

    public var id: String { return self.rawValue }
    public static var allOptions: [String] {
        return StatusBarTabType.allCases.map { $0.rawValue.capitalized }
    }
}


Review comment (suggestion):
I think we can write this using keyPaths, should look like: 
`StatusBarTabType.allCases.map(\.rawValue.capitalized)`

Code after:
//
//  StatusBarTabType.swift
//  CodeEditModules/StatusBar
//
//  Created by Lukas Pistrol on 11.05.22.
//

import Foundation

/// A collection of types describing possible tabs in the Status Bar.
public enum StatusBarTabType: String, CaseIterable, Identifiable {
    case terminal
    case debugger
    case output

    public var id: String { self.rawValue }
    public static var allOptions: [String] {
        return StatusBarTabType.allCases.map(\.rawValue.capitalized)
    }
}
Repository: CodeEditApp/CodeEdit
File: CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineMenu.swift (Swift)

Code before:
    /// Action that opens **Finder** at the items location.
    @objc
    private func showInFinder() {
        item?.showInFinder()
    }

    /// Action that opens the item, identical to clicking it.
    @objc
    private func openInTab() {
        if let item = item {
            workspace?.openTab(item: item)
        }
    }

    /// Action that opens in an external editor
    @objc
    private func openWithExternalEditor() {
        item?.openWithExternalEditor()
    }

    // TODO: allow custom file names
    /// Action that creates a new untitled file
    @objc
    private func newFile() {
        item?.addFile(fileName: "untitled")
    }

    // TODO: allow custom folder names
    /// Action that creates a new untitled folder
    @objc
    private func newFolder() {
        item?.addFolder(folderName: "untitled")
    }

    /// Action that deletes the item.
    @objc
    private func delete() {
        item?.delete()
    }

    /// Action that duplicates the item
    @objc
    private func duplicate() {
        item?.duplicate()
    }
}

extension NSMenuItem {
    fileprivate static func none() -> NSMenuItem {
        let item = NSMenuItem(title: "<None>", action: nil, keyEquivalent: "")
        item.isEnabled = false

Review comment (bug):
If a file already exists it will crash with:

> Thread 1: Fatal error: Duplicate keys of type 'FileItem' were found in a Dictionary.

Code after:
    /// Action that opens **Finder** at the items location.
    @objc
    private func showInFinder() {
        item?.showInFinder()
    }

    /// Action that opens the item, identical to clicking it.
    @objc
    private func openInTab() {
        if let item = item {
            workspace?.openTab(item: item)
        }
    }

    /// Action that opens in an external editor
    @objc
    private func openWithExternalEditor() {
        item?.openWithExternalEditor()
    }

    // TODO: allow custom file names
    /// Action that creates a new untitled file
    @objc
    private func newFile() {
        item?.addFile(fileName: "untitled")
        outlineView.expandItem((item?.isFolder ?? true) ? item : item?.parent)
    }

    // TODO: allow custom folder names
    /// Action that creates a new untitled folder
    @objc
    private func newFolder() {
        item?.addFolder(folderName: "untitled")
        outlineView.expandItem(item)
        outlineView.expandItem((item?.isFolder ?? true) ? item : item?.parent)
    }

    /// Action that deletes the item.
    @objc
    private func delete() {
        item?.delete()
    }

    /// Action that duplicates the item
    @objc
    private func duplicate() {
        item?.duplicate()
    }
}

extension NSMenuItem {
Repository: CodeEditApp/CodeEdit
File: CodeEditModules/Modules/AppPreferences/src/Sections/GeneralPreferences/GeneralPreferencesView.swift (Swift)

Code before:
//
//  GeneralPreferencesView.swift
//  CodeEditModules/AppPreferences
//
//  Created by Lukas Pistrol on 30.03.22.
//

import SwiftUI
import CodeEditUI
import Sparkle

/// A view that implements the `General` preference section
public struct GeneralPreferencesView: View {
    @StateObject private var updater = ObservableUpdater()

    private let inputWidth: Double = 160
    private let textEditorWidth: Double = 220
    private let textEditorHeight: Double = 30

    @StateObject
    private var prefs: AppPreferencesModel = .shared

    @State
    private var openInCodeEdit: Bool = true

    public init() {
        guard let defaults = UserDefaults.init(
            suiteName: "austincondiff.CodeEdit.shared"
        ) else {
            print("Failed to get/init shared defaults")
            return
        }

        self.openInCodeEdit = defaults.bool(forKey: "enableOpenInCE")
    }

    public var body: some View {
        PreferencesContent {
            appearanceSection

Review comment (suggestion):
Unless I'm missing something, I think unless `GeneralPreferencesView` get initialized at the start of your app - the updater won't get initialized and therefore won't automatically check for updates. 

Code after:
//
//  GeneralPreferencesView.swift
//  CodeEditModules/AppPreferences
//
//  Created by Lukas Pistrol on 30.03.22.
//

import SwiftUI
import CodeEditUI
import Sparkle

/// A view that implements the `General` preference section
public struct GeneralPreferencesView: View {
    @EnvironmentObject var updater: SoftwareUpdater

    private let inputWidth: Double = 160
    private let textEditorWidth: Double = 220
    private let textEditorHeight: Double = 30

    @StateObject
    private var prefs: AppPreferencesModel = .shared

    @State
    private var openInCodeEdit: Bool = true

    public init() {
        guard let defaults = UserDefaults.init(
            suiteName: "austincondiff.CodeEdit.shared"
        ) else {
            print("Failed to get/init shared defaults")
            return
        }

        self.openInCodeEdit = defaults.bool(forKey: "enableOpenInCE")
    }

    public var body: some View {
        PreferencesContent {
            appearanceSection
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Contributors/ContributorsView.swift (Swift)

Code before:
//
//  ContributorsView.swift
//  CodeEdit
//
//  Created by Lukas Pistrol on 19.01.23.
//

import SwiftUI

struct ContributorsView: View {

    @StateObject private var viewModel = ContributorsViewModel()
    @State private var displayDivider = false

    var body: some View {
        VStack(spacing: 0) {
            Image(nsImage: NSApp.applicationIconImage)
                .resizable()
                .frame(width: 70, height: 70)
            Text("Contributors")
                .font(.largeTitle)
                .fontWeight(.bold)
                .padding(.vertical, 8)
            Divider()
                .opacity(displayDivider ? 1 : 0)
            OffsettableScrollView(showsIndicator: false) { offset in
                displayDivider = offset.y < 0
            } content: {
                LazyVStack(spacing: 0) {
                    ForEach(viewModel.contributors) { contributor in
                        ContributorRowView(contributor: contributor)
                        Divider()
                            .padding(.horizontal)
                    }
                }
            }
        }
        .frame(width: 350, height: 500)
        .background(.regularMaterial)
        .task {
            viewModel.loadContributors()
        }
    }


Review comment (suggestion):
Should be 48x48...
```suggestion
                .frame(width: 48, height: 48)
```

Code after:
//
//  ContributorsView.swift
//  CodeEdit
//
//  Created by Lukas Pistrol on 19.01.23.
//

import SwiftUI

struct ContributorsView: View {

    @StateObject private var viewModel = ContributorsViewModel()
    @State private var displayDivider = false

    var body: some View {
        VStack(spacing: 0) {
            Image(nsImage: NSApp.applicationIconImage)
                .resizable()
                .frame(width: 48, height: 48)
            Text("Contributors")
                .font(.title)
                .padding(.vertical, 8)
            Divider()
                .opacity(displayDivider ? 1 : 0)
            OffsettableScrollView(showsIndicator: false) { offset in
                displayDivider = offset.y < 0
            } content: {
                LazyVStack(spacing: 0) {
                    ForEach(viewModel.contributors) { contributor in
                        ContributorRowView(contributor: contributor)
                        Divider()
                            .frame(height: 0.5)
                            .opacity(0.5)
                            .padding(.horizontal)
                    }
                }
            }
        }
        .frame(width: 280, height: 400)
        .background(.regularMaterial)
        .task {
            viewModel.loadContributors()
        }
    }