Skip to content

Unable to correct protocol extension after erroneous attempt in Swift REPL #62785

Open
@Stiivi

Description

@Stiivi

Description

Using REPL, when a wrong conformance to a protocol is specified in an extension, subsequent extensions with a correct conformance are rejected.

Steps to reproduce

  1. Start swift repl
  2. Define a protocol: protocol Boo { func boo() }
  3. Define wrongly a protocol extension conformance: extension Int: Boo {}. Correct error is raised:
expression failed to parse:
error: repl.swift:2:1: error: type 'Int' does not conform to protocol 'Boo'
extension Int: Boo {}
^

repl.swift:1:21: note: protocol requires function 'boo()' with type '() -> ()'
protocol Boo { func boo() }
                    ^
  1. Provide correct conformance: extension Int: Boo { public func boo() {} }

Results in an error:

  2> extension Int: Boo { public func boo() {} } 
expression failed to parse:
error: repl.swift:2:16: error: redundant conformance of 'Int' to protocol 'Boo'
extension Int: Boo { public func boo() {} }
               ^

repl.swift:2:1: note: 'Int' declares conformance to protocol 'Boo' here
extension Int: Boo {}
^

Expected behavior

No error should be raised after the last correct protocol extension implementation.

Full REPL session:

Welcome to Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51).
Type :help for assistance.
  1> protocol Boo { func boo() } 
  2> extension Int: Boo {} 
expression failed to parse:
error: repl.swift:2:1: error: type 'Int' does not conform to protocol 'Boo'
extension Int: Boo {}
^

repl.swift:1:21: note: protocol requires function 'boo()' with type '() -> ()'
protocol Boo { func boo() }
                    ^


  2> extension Int: Boo { public func boo() {} } 
expression failed to parse:
error: repl.swift:2:16: error: redundant conformance of 'Int' to protocol 'Boo'
extension Int: Boo { public func boo() {} }
               ^

repl.swift:2:1: note: 'Int' declares conformance to protocol 'Boo' here
extension Int: Boo {}
^

Correct session:

Welcome to Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51).
Type :help for assistance.
  1> protocol Boo { func boo() } 
  2> extension Int: Boo { public func boo() {} } 
  3>  

Environment

  • Swift compiler version info: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51) Target: x86_64-apple-macosx12.0
  • Xcode version info Xcode 14.2 Build version 14C18
  • Deployment target: MacOS 12.6.1 (21G217)

Metadata

Metadata

Assignees

No one assigned

    Labels

    REPLbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformances

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions