mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSDiagnostics] Add diagnostics for two kinds of incorrect initializer reference
- Attempting to construct class object using metatype value via non-required initializer - Referencing initializer of protocol metatype base Both of the diagnostics are used by `AllowInvalidInitRef` fix.
This commit is contained in:
@@ -1506,3 +1506,27 @@ bool PartialApplicationFailure::diagnoseAsError() {
|
||||
emitDiagnostic(anchor->getNameLoc(), diagnostic, kind);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InvalidDynamicInitOnMetatypeFailure::diagnoseAsError() {
|
||||
auto *anchor = getRawAnchor();
|
||||
emitDiagnostic(anchor->getLoc(), diag::dynamic_construct_class,
|
||||
BaseType->getMetatypeInstanceType())
|
||||
.highlight(BaseRange);
|
||||
emitDiagnostic(Init, diag::note_nonrequired_initializer, Init->isImplicit(),
|
||||
Init->getFullName());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InitOnProtocolMetatypeFailure::diagnoseAsError() {
|
||||
auto *anchor = getRawAnchor();
|
||||
if (IsStaticallyDerived) {
|
||||
emitDiagnostic(anchor->getLoc(), diag::construct_protocol_by_name,
|
||||
BaseType->getMetatypeInstanceType())
|
||||
.highlight(BaseRange);
|
||||
} else {
|
||||
emitDiagnostic(anchor->getLoc(), diag::construct_protocol_value, BaseType)
|
||||
.highlight(BaseRange);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user