Xcode-beta (7A121l): Compiler Crash when attempting to implement a struct and a conform to a generic protocol
| Originator: | owensd | ||
| Number: | rdar://21559587 | Date Originated: | 25-Jun-2015 09:21 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-beta (7A121l) |
| Classification: | Other Bug | Reproducible: | Always |
The code below causes an Abort 6 trap:
— Code —
import Foundation
public enum TokenizerError<T> : ErrorType {
case Error(message: String, offset: T)
}
public struct Token<ContentType, ContentIndexType> {
public init(token: ContentType, startOffset: ContentIndexType, endOffset: ContentIndexType) {
self.token = token
self.startOffset = startOffset
self.endOffset = endOffset
}
public let token: ContentType
public let startOffset: ContentIndexType
public let endOffset: ContentIndexType
}
public protocol TokenizerType {
typealias ContentType
typealias ContentIndexType
var rules: [(content: ContentType, offset: ContentIndexType) -> ContentIndexType?] { get }
var content: ContentType { get }
init(content: ContentType)
func next(index: ContentIndexType?) throws -> (token: Token<ContentType, ContentIndexType>, nextIndex: ContentIndexType)?
}
public struct StringTokenizer : TokenizerType {
public let rules: [(content: String, offset: String.Index) -> String.Index?] = []
public let content: String = ""
public init(content: String) {
}
public func next(index: String.Index? = nil) throws -> (token: Token<String, String.Index>, nextIndex: String.Index)? {
precondition(rules.count > 0, "There are no rules specified for your tokenizer.")
let startAt = index ?? content.characters.startIndex
for rule in rules {
if let nextIndex = rule(content: content, offset: startAt) {
let tokenString = String(content.characters[startAt...nextIndex])
let token = Token(token: tokenString, startOffset: startAt, endOffset: nextIndex)
return (token: token, nextIndex: nextIndex.successor())
}
}
throw TokenizerError.Error(message: "", offset: self.content.characters.startIndex)
}
}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!