swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
66.77k stars 10.29k forks source link

[SR-13253] Compiler hangs building invalid code #55693

Open swift-ci opened 3 years ago

swift-ci commented 3 years ago
Previous ID SR-13253
Radar https://feedbackassistant.apple.com/feedback/8066568
Original Reporter dmehers (JIRA User)
Type Bug

Attachment: Download

Environment Xcode Version 12.0 beta 2 (12A6163b) Apple Swift version 5.3 (swiftlang-1200.0.16.13 clang-1200.0.22.25) Target: x86_64-apple-darwin19.6.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | None | |Priority | Medium | md5: 58be4b51ed610315d0ccc118ec7f11f6

Issue Description:

I'm getting a hang compiling the attached invalid code:

/Applications/Xcode_12_beta_2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift /Users/damian/Downloads/test/test/ContentView.swift
/Users/damian/Downloads/test/test/ContentView.swift:9:25: error: cannot find 'totalseconds' in scope
let hours = totalseconds / 3600
^\~\~\~\~\~\~\~\~\~\~\~
/Users/damian/Downloads/test/test/ContentView.swift:10:29: error: cannot find 'totalseconds' in scope
let remaining = totalseconds % 3600
^\~\~\~\~\~\~\~\~\~\~\~

...hangs

import SwiftUI

struct TimeElapsedView: View {
    let interval : DateInterval

    var body : some View {
        HStack {
            let totalSeconds = Int(interval.duration)
            let hours = totalseconds / 3600
            let remaining = totalseconds % 3600
            let minutes = remaining / 60
            let seconds = remaining % 60

        }
    }
}

struct TimeElapsedView_Previews: PreviewProvider {
    static var previews: some View {
        TimeElapsedView()
    }
}
theblixguy commented 3 years ago

On master, the compiler doesn't hang for me and produces the following diagnostics:

/Users/spare/Desktop/test.swift:9:25: error: cannot find 'totalseconds' in scope
            let hours = totalseconds / 3600
                        ^~~~~~~~~~~~
/Users/spare/Desktop/test.swift:10:29: error: cannot find 'totalseconds' in scope
            let remaining = totalseconds % 3600
                            ^~~~~~~~~~~~
/Users/spare/Desktop/test.swift:7:9: error: type of expression is ambiguous without more context
        HStack {
        ^~~~~~~~
/Users/spare/Desktop/test.swift:20:25: error: missing argument for parameter 'interval' in call
        TimeElapsedView()
                        ^
                        interval: <#DateInterval#>
/Users/spare/Desktop/test.swift:3:8: note: 'init(interval:)' declared here
struct TimeElapsedView: View {
       ^

Could you verify using the latest trunk snapshot from swift.org?

swift-ci commented 3 years ago

Comment by Damian Mehers (JIRA)

Looks better with 16 Jul dev snapshot:

damian@Damians-iMac-Pro-3 ~ % swift --version
Apple Swift version 5.3 (swiftlang-1200.0.16.13 clang-1200.0.22.25)
Target: x86_64-apple-darwin19.6.0
damian@Damians-iMac-Pro-3 ~ % swift /Users/damian/Downloads/test/test/ContentView.swift
/Users/damian/Downloads/test/test/ContentView.swift:9:25: error: cannot find 'totalseconds' in scope
            let hours = totalseconds / 3600
                        ^~~~~~~~~~~~
/Users/damian/Downloads/test/test/ContentView.swift:10:29: error: cannot find 'totalseconds' in scope
            let remaining = totalseconds % 3600
                            ^~~~~~~~~~~~
// HANGING

^C
damian@Damians-iMac-Pro-3 ~ % export PATH=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-07-16-a.xctoolchain/usr/bin::"${PATH}"
damian@Damians-iMac-Pro-3 ~ % swift --version                                                                                                 
Apple Swift version 5.3-dev (LLVM a2e0564af78e841, Swift 1224d8b2d312c55)
Target: x86_64-apple-darwin19.6.0
damian@Damians-iMac-Pro-3 ~ % swift /Users/damian/Downloads/test/test/ContentView.swift                                                       
/Users/damian/Downloads/test/test/ContentView.swift:9:25: error: cannot find 'totalseconds' in scope
            let hours = totalseconds / 3600
                        ^~~~~~~~~~~~
/Users/damian/Downloads/test/test/ContentView.swift:10:29: error: cannot find 'totalseconds' in scope
            let remaining = totalseconds % 3600
                            ^~~~~~~~~~~~
/Users/damian/Downloads/test/test/ContentView.swift:7:9: error: type of expression is ambiguous without more context
        HStack {
        ^~~~~~~~
/Users/damian/Downloads/test/test/ContentView.swift:20:25: error: missing argument for parameter 'interval' in call
        TimeElapsedView()
                        ^
                        interval: <#DateInterval#>
/Users/damian/Downloads/test/test/ContentView.swift:3:8: note: 'init(interval:)' declared here
struct TimeElapsedView: View {
       ^
damian@Damians-iMac-Pro-3 ~ %