Skip to content

Compiler lacks warnings for redeclaring properties in protocols #63821

Open
@miku1958

Description

@miku1958

Currently, the compiler allows to build this code:

protocol TestDelegate1 {
	var name: NSObject { get }
}

protocol TestDelegate2: TestDelegate1 {
	var name: NSString { get }
}

But it does not allow adding overrides to TestDelegate2 and it doesn't allow to has redeclaration properties in class/struct... I don't know if it is a limitation or a bug

The only solution for now is to add an extension to TestDelegate2 that implements var name: NSObject in it like:

extension TestDelegate2 {
	var name: NSObject {
		fatalError("not support")
	}
}

struct TestClass: TestDelegate2 {
	var name: NSString = ""
}

But the compiler does not warn about this any at all, it just gives some unhelpful errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesdiagnostics QoIBug: Diagnostics Quality of Implementationmissing warningBug: Missing warningprotocolFeature → type declarations: Protocol declarationsswift 5.9type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions