-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfperformanceregressionswift 4.0type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
Previous ID | SR-5950 |
Radar | None |
Original Reporter | kam (JIRA User) |
Type | Bug |
Environment
Xcode 9
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, 4.0Regression, TypeChecker |
Assignee | None |
Priority | Medium |
md5: 124233556cc025b223c538070e322846
Issue Description:
The following code compiles fine on Swift 3.1 in Xcode 8.3.3:
import Foundation
struct Calculator {
let tCrit: Double
let predictedValue: ([Double]) -> Double
}
// variable indices
let index1 = 0
let index2 = 1
let index3 = 2
let calc1 = Calculator(
tCrit: 1.962,
predictedValue: { (parameters: [Double]) -> Double in
return -603 + 123.31 * parameters[index1] + 9.288 * parameters[index2] + 0.316 * parameters[index3]
}
)
let calc2 = Calculator(
tCrit: 1.962,
predictedValue: { parameters in
-302.908 + 0.162 * parameters[index1] + 3.112 * parameters[index2] + 0.392 * parameters[index3]
})
let calc3 = Calculator(
tCrit: 1.962,
predictedValue: { parameters in
-992 + 1.312 * parameters[index1] + 1.235 * parameters[index2]
})
let calc4 = Calculator(
tCrit: 1.962,
predictedValue: { parameters in
-2932.32 + 1.253 * parameters[index1] + 3.212 * parameters[index2]
})
In Swift 3.2, it gets the following errors:
/Users/kevin/Desktop/TestClosures/TestClosures/TestClosures.swift:14:13: error: expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
let calc1 = Calculator(
^~~~~~~~~~~
/Users/kevin/Desktop/TestClosures/TestClosures/TestClosures.swift:25:38: error: type 'Double' has no subscript members
-302.908 + 0.162 * parameters[index1] + 3.112 * parameters[index2] + 0.392 * parameters[index3]
~~~~~~~~~~^~~~~~~~
/Users/kevin/Desktop/TestClosures/TestClosures/TestClosures.swift:39:38: error: type 'Double' has no subscript members
-2932.32 + 1.253 * parameters[index1] + 3.212 * parameters[index2]
~~~~~~~~~~^~~~~~~~
I would expect that declaring the parameters and return type in the closure would help clear things up, but it seems to have made it worse.
Metadata
Metadata
Assignees
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfperformanceregressionswift 4.0type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis