Open
Description
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
- Start
swift repl
- Define a protocol:
protocol Boo { func boo() }
- 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() }
^
- 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)