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-14985] Compiler warning of 'nearly matched' default protocol requirement in extension #57327

Open
Mordil opened this issue Jul 29, 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 Jul 29, 2021

Previous ID SR-14985
Radar rdar://problem/81277877
Original Reporter @Mordil
Type Bug
Environment

This reproduces in Swift 5.2, 5.3, 5.4, and 5.5 as of Xcode 13 Beta 1 (13A5154h)

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

md5: 192ed9136566057f1be0fa4572a0db2f

Issue Description:

The following code shows a difference in how the compiler treats protocol conformances when the requirement is a defaulted one and the conformer's implementation is an optional covariant, depending on if it's provided in the base implementation or an extension

This is surprising and "annoying" as it disallows certain practices of grouping code

protocol Base {
    var optionalRequirement: String? { get }
}
extension Base {
    var optionalRequirement: String? { nil }
}

class ImplementationA: Base {
    var optionalRequirement: String { "no compiler warning" }
}

class ImplementationB {
    var optionalRequirement: String { "also no compiler warning" }
}
extension ImplementationB: Base { }

class ImplementationC { }
extension ImplementationC: Base {
    var optionalRequirement: String { "compiler warning" }
    // Property 'optionalRequirement' nearly matches defaulted requirement 'optionalRequirement' of protocol 'Base'
}
@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