Skip to content
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-1158] Sub-subclass doesn't conform to protocol #43766

Closed
swift-ci opened this issue Apr 4, 2016 · 9 comments
Closed

[SR-1158] Sub-subclass doesn't conform to protocol #43766

swift-ci opened this issue Apr 4, 2016 · 9 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 4, 2016

Previous ID SR-1158
Radar None
Original Reporter diegosanchezr (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, OptimizedOnly
Assignee @jckarter
Priority Medium

md5: 88d26548a43585e6ea0dfa127129503d

Issue Description:

Module 1:

public protocol MyProtocol  {}
public class ClassLevel1: MyProtocol {
    public init() {}
}
public class ClassLevel2: ClassLevel1 {
    public override init () {}
}

Modue 2:

class ClassLevel3: ClassLevel2 {
    override init() {
        super.init()
    }
}

func createClassLevel3() -> MyProtocol {
    let class3 =  ClassLevel3()
    return class3 // <- Compiler error. Says doesn't conform to MyProtocol
}

Workaround:

func createClassLevel3() -> MyProtocol {
    let class3 =  ClassLevel3()
    return class3 as! MyProtocol
}

Only happens with whole-module-optimization. Affected versions: swift-2.2, swift-2.2.1-SNAPSHOT-2016-03-28-a.

Doesn't affect swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 4, 2016

Comment by Diego (JIRA)

Related: badoo/Chatto#60

As this seems to be solved in master, is there any chance to cherry-pick the fix for swift-2.2.1?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 4, 2016

Comment by Diego (JIRA)

Also, in the screenshot in badoo/Chatto#60 the error message says "DemoMessagePresenter.swift:124:38: error: cannot convert value of type 'InteractionHandlerT?' to expected argument type '_?'" which is quite misleading. In that screenshot-code, taking the return value into a let variable changes the error to "Return expression of type 'DemoMessagePresenter<ViewModelBuilderT, InteractionHandlerT>' does not conform to 'ChatItemPresenterProtocol'" which is more sensible.

@belkadan
Copy link
Contributor

belkadan commented Apr 5, 2016

@atrick, any idea which recent commit might have fixed this?

@jckarter
Copy link
Member

jckarter commented Apr 5, 2016

diegosanchezr (JIRA User), would you be able to provide a project that reproduces the problem? I was trying to put together a test case, but I can't get it to fail against swift-2.2-branch:

diff --git a/test/decl/class/Inputs/inheritance_protocol_multi_file_2.swift b/test/decl/class/Inputs/inheritance_protocol_multi_file_2.swift
new file mode 100644
index 0000000..3180548
--- /dev/null
+++ b/test/decl/class/Inputs/inheritance_protocol_multi_file_2.swift
@@ -0,0 +1,10 @@
+class ClassLevel3: ClassLevel2 {
+    override init() {
+        super.init()
+    }
+}
+
+public func createClassLevel3() -> MyProtocol {
+    let class3 =  ClassLevel3()
+    return class3 // <- Compiler error. Says doesn't conform to MyProtocol
+}
diff --git a/test/decl/class/inheritance_protocol_multi_file.swift b/test/decl/class/inheritance_protocol_multi_file.swift
new file mode 100644
index 0000000..179bc5d
--- /dev/null
+++ b/test/decl/class/inheritance_protocol_multi_file.swift
@@ -0,0 +1,12 @@
+// RUN: %target-swift-frontend -parse -verify -primary-file %s %S/Inputs/inheritance_protocol_multi_file_2.swift
+// RUN: %target-swift-frontend -parse -verify %s -primary-file %S/Inputs/inheritance_protocol_multi_file_2.swift
+// RUN: %target-swift-frontend -emit-ir -verify -whole-module-optimization %s %S/Inputs/inheritance_protocol_multi_file_2.swift && false
+// RUN: %target-swift-frontend -emit-ir -verify -whole-module-optimization %S/Inputs/inheritance_protocol_multi_file_2.swift %s
+
+public protocol MyProtocol  {}
+public class ClassLevel1: MyProtocol {
+    public init() {}
+}
+public class ClassLevel2: ClassLevel1 {
+    public override init () {}
+}

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 5, 2016

Comment by Diego (JIRA)

@jckarter Take a look at Example.zip. When I mean different modules I mean frameworks, not just different files

@jckarter
Copy link
Member

jckarter commented Apr 5, 2016

Thanks for the clarification diegosanchezr (JIRA User).

@jckarter
Copy link
Member

jckarter commented Apr 5, 2016

Got a reproducer. Only affects swift-2.2-branch, not master:

diff --git a/test/decl/class/Inputs/inheritance_protocol_multi_module_2.swift b/test/decl/class/Inputs/inheritance_protocol_multi_module_2.swift
new file mode 100644
index 0000000..7a6ebb4
--- /dev/null
+++ b/test/decl/class/Inputs/inheritance_protocol_multi_module_2.swift
@@ -0,0 +1,12 @@
+import Mod
+
+class ClassLevel3: ClassLevel2 {
+    override init() {
+        super.init()
+    }
+}
+
+public func createClassLevel3() -> MyProtocol {
+    let class3 =  ClassLevel3()
+    return class3 // <- Compiler error. Says doesn't conform to MyProtocol
+}
diff --git a/test/decl/class/inheritance_protocol_multi_module.swift b/test/decl/class/inheritance_protocol_multi_module.swift
new file mode 100644
index 0000000..cb4b029
--- /dev/null
+++ b/test/decl/class/inheritance_protocol_multi_module.swift
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %target-swift-frontend -emit-module-path %t/Mod.swiftmodule -module-name Mod %s
+// RUN: %target-swift-frontend -parse -verify -I %t %S/Inputs/inheritance_protocol_multi_module_2.swift
+
+/* module Mod */
+
+public protocol MyProtocol  {}
+public class ClassLevel1: MyProtocol {
+    public init() {}
+}
+public class ClassLevel2: ClassLevel1 {
+    public override init () {}
+}

@jckarter
Copy link
Member

jckarter commented Apr 6, 2016

Testing a fix (borrowed from @bitjammer's fix to master): #2075

@swift-ci
Copy link
Collaborator Author

Comment by Diego (JIRA)

Confirming it's fixed in swift-2.2.1-SNAPSHOT-2016-04-12-a, thank u

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

3 participants