swiftlang / swift

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

[SR-2716] Crash emitting error within string-interpolated expression #45320

Closed swift-ci closed 8 years ago

swift-ci commented 8 years ago
Previous ID SR-2716
Radar rdar://problem/27830834
Original Reporter AGWorld (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment xcrun swift -version \>\>\> Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38) \>\>\> Target: x86_64-apple-macosx10.9 XCode Version 8.0 (8A218a) MacBook Air 13, OS X El Capitan 10.11.6
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, TypeChecker | |Assignee | AGWorld (JIRA) | |Priority | Medium | md5: a658be66382c1ffba5504a7f270e9029

Issue Description:

I creating the app using MapKit framework.

Sample code that don't compile:

import MapKit
MKDirections(request: MKDirectionsRequest()).calculate { (response, error) in
            guard let response = response else {
                return
            }

            response.routes.forEach({ (route) in
                print("\(route.distance)\n")
            })

            print("Selected route distance: \(response.routes.minElement{ $0 < $1 }!.distance)")
        }

Last print line can't recognized by swift compiler.

belkadan commented 8 years ago
   Assertion failed: (TypeVariables[impl.getGraphIndex()] == typeVar && "Type variable mismatch"), function lookupNode, file /Volumes/Data/swift-public/swift/lib/Sema/ConstraintGraph.cpp, line 52.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -interpret - -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name main 
1.  While type-checking expression at [<stdin>:2:1 - line:12:9] RangeText="MKDirections(request: MKDirectionsRequest()).calculate { (response, error) in
            guard let response = response else {
                return
            }

            response.routes.forEach({ (route) in
                print("\(route.distance)\n")
            })

            print("Selected route distance: \(response.routes.minElement{ $0 < $1 }!.distance)")
        }"
2.  While type-checking expression at [<stdin>:11:13 - line:11:96] RangeText="print("Selected route distance: \(response.routes.minElement{ $0 < $1 }!.distance)")"
3.  While type-checking expression at [<stdin>:11:18 - line:11:96] RangeText="("Selected route distance: \(response.routes.minElement{ $0 < $1 }!.distance)")"
belkadan commented 8 years ago

Taking the interpolated expression out of the string results in this error, which hopefully gets you unblocked:

<stdin>:11:48: error: binary operator '<' cannot be applied to two 'MKRoute' operands
            _ = response.routes.minElement{ $0 < $1 }!.distance
                                            ~~ ^ ~~
rudkx commented 8 years ago

I'm looking into this now. I think I know what's going on.

rudkx commented 8 years ago

Fixed in master: https://github.com/apple/swift/commit/675e542f3b7b523adf299518470b7b0eefbc124e

rudkx commented 8 years ago

Agafonov, can you verify that this is fixed, and then close out the bug if so, using one a future snapshot build?