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-14843] Cannot declare protocol conformance in REPL following invalid declaration, types become inconsistent #4309

Open
swift-ci opened this issue Jun 28, 2021 · 1 comment
Labels
bug Something isn't working LLDB for Swift

Comments

@swift-ci
Copy link

Previous ID SR-14843
Radar rdar://problem/79922194
Original Reporter palle (JIRA User)
Type Bug
Environment

swift-driver version: 1.26 Apple Swift version 5.5 (swiftlang-1300.0.20.104 clang-1300.0.21.1)
Target: x86_64-apple-macosx12.0

macOS 12.0 Beta (21A5248p)
Xcode 13.0 beta (13A5155e)

Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Bug
Assignee None
Priority Medium

md5: 06bb3073af23d7520736a35596a0eb6d

Issue Description:

Description

When declaring protocol conformance using an extension, it is not possible to redeclare that extension, regardless of whether the first declaration was successful or failed due to compilation errors.

This makes it difficult to quickly fix errors by modifying the broken extension and furthermore leaves types in an inconsistent state, where they are reported as being conformant but do not have required members.

Expected results:

When declaring an extension that declares protocol conformance, the extended type should not become conformant to that extension if the extension has compilation errors.

Example:

 $ swift
 Welcome to Apple Swift version 5.5 (swiftlang-1300.0.20.104 clang-1300.0.21.1).
 Type :help for assistance.
 1> struct Foo { 
 2. }

 3> extension Foo: CustomStringConvertible {}
 error: repl.swift:3:1: error: type 'Foo' does not conform to protocol 'CustomStringConvertible'
 extension Foo: CustomStringConvertible {}
 ^

Swift.CustomStringConvertible:2:9: note: protocol requires property 'description' with type 'String'
 var description: String

{ get }

^

3> extension Foo: CustomStringConvertible { 
4.     public var description: String { 
5.         return "Foo" 
6.     }
7. } 
 error: repl.swift:3:16: error: redundant conformance of 'Foo' to protocol 'CustomStringConvertible'
 extension Foo: CustomStringConvertible {
 ^

repl.swift:3:1: note: 'Foo' declares conformance to protocol 'CustomStringConvertible' here
 extension Foo: CustomStringConvertible {}
 ^

 

First, an invalid conformance is declared for CustomStringConvertible (missing description property).

This causes an error to be reported, but Foo is still marked as being conformant to CustomStringConvertible. (Foo() is CustomStringConvertible evaluates to true)

When declaring a function, such as

func bar(_ x: CustomStringConvertible) {
    print(x.description)
}

and calling it with an instance of Foo following the initial, broken conformance declaration, a symbol lookup error is raised:

error: Couldn't lookup symbols:
  protocol conformance descriptor for __lldb_expr_1.Foo : Swift.CustomStringConvertible in __lldb_expr_3
@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LLDB for Swift
Projects
None yet
Development

No branches or pull requests

2 participants