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-14467] Protocol inheritance with optional covariance does not produce compiler error #56823

Open
Mordil opened this issue Apr 9, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@Mordil
Copy link

Mordil commented Apr 9, 2021

Previous ID SR-14467
Radar rdar://problem/76546637
Original Reporter @Mordil
Type Bug

Attachment: Download

Environment

macOS 11.2.3

Apple Swift version 5.4 (swiftlang-1205.0.24.6 clang-1205.0.19.54)
Target: x86_64-apple-darwin20.3.0

Xcode 12.5 Beta 2 (12E5234g)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 4faca14f1ca51cfa8c832fdfacab5415

Issue Description:

When you have the following protocol structure

protocol Base {
  var property: String? { get }
}

protocol Derived: Base {
  var property: String { get }
} 

The compiler does not provide an error at the definition of the protocol.

It's not until you try conforming to it do you get conflicting and unresolvable compiler errors:

struct Conformance: Derived { // Type 'Conformance' does not conform to protocol 'Base'
  // add stubs fix-it adds 'var property: String?' which adds a redeclaration error
  var property: String { "some value" }
}

I would expect the compiler to catch this covariance issue with Optional and throw an error at the protocol declaration

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler in itself label Dec 13, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants