New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-6730] SILgen segmentation fault #49279
Comments
@swift-ci create |
Does not crash on master:
That last part looks like the real issue, and I think @xedin fixed that a while back. Pavel? |
@belkadan how about when you replace it to compactMap? |
Sorry, you're right. The crash may be fixed, but either the whole thing should type-check or it should refuse to let you call |
> or it should refuse to let you call skipNil in the first place. LOL, interestingly, in my project some of these properties were optional, which is why I was calling skipNil(). When I reduced the crasher, I forgot about that detail and didn't check since I got the same crash without optionals anyway 😛 Does this type check in master if some of the properties are optional? |
Oh but I see what was wrong in my code in the first place, I needed as [A?]. This is what happens when I need to do mental gymnastics to figure out what stupid thing I did rather than a robust diagnostic system helping me :/ |
Diagnostic is pretty bad here which is a consequence of us trying to diagnose bottom-up in the AST... |
Better error here would be "type 'A' does not conform to protocol 'OptionalProtocol'" which points to "skipNil()". |
Agreed, but note that this crash happened with this code too (which is what my project had): import Foundation
public protocol OptionalProtocol {
associatedtype Wrapped
var optional: Wrapped? { get }
}
extension Optional: OptionalProtocol {
public var optional: Wrapped? {
return self
}
}
public extension Sequence where Element: OptionalProtocol {
func skipNil() -> [Element.Wrapped] {
return self
.flatMap { $0.optional }
}
}
class A {}
class A1: A {}
class A2: A {}
class A3: A {}
final class V {
init() {
([
self.a1, self.a2, self.a3
] as [A])
.skipNil()
.forEach { self.f($0) }
}
func f(_ a: A) {}
private let a1 = A1()
private let a2: A2? = A2() // Note this changed from the original code in the Jira
private let a3 = A3()
} In this case the diagnostic (instead of the crash, I wonder if this also crashes in master still) should be that not all elements of that array literal are non-optional (however that should be worded). |
Code from your comment doesn't crash on master. As for the diagnostic I think it should be "cannot convert value of type 'A2?' to expected element type 'A'" which points to the "self.a2" element of the array. |
👍 |
Environment
Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Additional Detail from JIRA
md5: 14e75aff971213fcb4f341e731528969
Issue Description:
Code:
Crash:
The text was updated successfully, but these errors were encountered: