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-7097] Swift 4.1 Crashing on Generic Types #49645
Comments
@swift-ci create |
I don't see a way to reproduce this (is there a project we can build?), but it looks a lot like SR-7072. |
calebkleveter (JIRA User), can you try the latest 4.1 development snapshot from https://swift.org/download/#snapshots, from February 27th or newer? This looks like the same failure we fixed yesterday for SR-7072, but I can't verify myself without building your project. |
@DougGregor If I'm not mistaken, he was already on the most recent snapshot when this crash happened. |
calebkleveter (JIRA User), do you have project sources you can attach? Without them, we're not able to reproduce the problem (or verify whether it was indeed fixed as part of SR-7072) |
Comment by Caleb Kleveter (JIRA) @DougGregor I was able to reproduce the issue with this project. I am not sure how much of this code actually contributes to the issue, as I don't have time to trim it down right now, but the Sources/App/Controllers/TodoController.swift and Sources/App/Models/Todo.swift are the files that would be of most interest. |
Comment by Caleb Kleveter (JIRA) I just tried to build the project I linked to above with the 03-1 snapshot, and it crashed with the same error message. |
calebkleveter (JIRA User), thank you! I'm able to reproduce the problem with your project. I don't have a fix yet, but this hack works around the crash for me: diff --git a/Sources/App/Controllers/TodoController.swift b/Sources/App/Controllers/TodoController.swift
index 5577da8..e3152c5 100644
--- a/Sources/App/Controllers/TodoController.swift
+++ b/Sources/App/Controllers/TodoController.swift
@@ -8,5 +8,5 @@ final class Controller<M: LargeProto> where M.ResolvedParameter == Future<M>, M.
typealias ContollerOne = Controller<ModelOne>
extension Router {
- func controller<Model>(at path: PathComponent..., controller: Controller<Model>.Type) {}
+ func controller<Model>(at path: PathComponent..., controller: Controller<Model>.Type) where Model.Database: QuerySupporting {}
} |
Way better workaround: diff --git a/Sources/App/Models/Todo.swift b/Sources/App/Models/Todo.swift
index a122349..17c8293 100644
--- a/Sources/App/Models/Todo.swift
+++ b/Sources/App/Models/Todo.swift
@@ -2,7 +2,7 @@ import FluentMySQL
import Vapor
import Foundation
-protocol LargeProto: Content, Model, Timestampable, SoftDeletable, Parameter, ResponseEncodable, Migration {
+protocol LargeProto: Content, Model, Timestampable, SoftDeletable, Parameter, ResponseEncodable, Migration where Self.Database == MySQLDatabase, Self.ID == Int {
var id: Self.ID? { get set }
var createdAt: Date? { get set }
@@ -11,9 +11,6 @@ protocol LargeProto: Content, Model, Timestampable, SoftDeletable, Parameter, Re
}
extension LargeProto {
- typealias Database = MySQLDatabase
- typealias ID = Int
-
static var idKey: Self.IDKey {
return \Self.id
} |
And here's a reduced test case: protocol P1 { }
protocol P2 {
associatedtype Assoc
}
protocol P3 : P2 { }
struct S0<M: P3> where M.Assoc: P1 { }
struct ConformsToP1: P1 { }
extension P3 {
typealias Assoc = ConformsToP1
}
protocol P5 { }
extension P5 {
func testSR7097<M>(_: S0<M>.Type) {}
} |
Attachment: Download
Environment
Additional Detail from JIRA
md5: b93b4a3f0b16de9abdfd2d2df0216ce7
Issue Description:
I am getting a compiler crash that appears to be an issue with generics. I have a protocol that conforms to multiple other protocols, some coming from the Vapor framework, some I built:
I then have a generic class that has some further restrictions:
And then I have an extension method on a protocol that takes in a controller:
This is the stack trace that I get from the compiler
This code worked in the Swift snapshot that was released with Xcode 9.3 beta, build 9Q107o (if I remember the build number correctly).
The text was updated successfully, but these errors were encountered: