Skip to content

Commit f7ddfa7

Browse files
committed
Improve "missing @differentiable attribute" diagnostic message.
Change phrasing to remove "blame" from the non-matching witness. Remove redundant DescriptiveDeclKind arguments.
1 parent e0bbcef commit f7ddfa7

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,11 +3113,9 @@ ERROR(overriding_decl_missing_differentiable_attr,none,
31133113
NOTE(protocol_witness_missing_differentiable_attr,none,
31143114
"candidate is missing attribute '%0'", (StringRef))
31153115
NOTE(protocol_witness_missing_differentiable_attr_other_file,none,
3116-
"%1 %2 must have explicit '%0' attribute to satisfy requirement %3 %4 (in "
3117-
"protocol %6) because it is declared in a different file than the "
3118-
"conformance of %5 to %6",
3119-
(StringRef, DescriptiveDeclKind, DeclName, DescriptiveDeclKind, DeclName,
3120-
Type, Type))
3116+
"candidate is missing explicit '%0' attribute to satisfy requirement %1 "
3117+
"(in protocol %3) because it is declared in a different file than the "
3118+
"conformance of %2 to %3", (StringRef, DeclName, Type, Type))
31213119

31223120
// @derivative
31233121
ERROR(derivative_attr_expected_result_tuple,none,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,11 +2461,8 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
24612461
diags
24622462
.diagnose(
24632463
witness,
2464-
diag::
2465-
protocol_witness_missing_differentiable_attr_other_file,
2466-
reqDiffAttrString, witness->getDescriptiveKind(),
2467-
witness->getName(), req->getDescriptiveKind(),
2468-
req->getName(), conformance->getType(),
2464+
diag::protocol_witness_missing_differentiable_attr_other_file,
2465+
reqDiffAttrString, req->getName(), conformance->getType(),
24692466
conformance->getProtocol()->getDeclaredInterfaceType())
24702467
.fixItInsert(match.Witness->getStartLoc(), reqDiffAttrString + ' ');
24712468
}

test/AutoDiff/Sema/ImplicitDifferentiableAttributeCrossFile/Inputs/other_file.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ protocol Protocol2: Differentiable {
3232

3333
struct ConformingStruct: Differentiable {
3434
// Error for missing `@differentiable` attribute.
35-
// expected-note @+1 {{instance method 'internalMethod1' must have explicit '@differentiable' attribute to satisfy requirement instance method 'internalMethod1' (in protocol 'Protocol1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'Protocol1'}} {{3-3=@differentiable }}
35+
// expected-note @+1 {{candidate is missing explicit '@differentiable' attribute to satisfy requirement 'internalMethod1' (in protocol 'Protocol1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'Protocol1'}} {{3-3=@differentiable }}
3636
func internalMethod1(_ x: Float) -> Float {
3737
x
3838
}
3939

4040
// Error for missing `@differentiable` superset attribute.
41-
// expected-note @+2 {{instance method 'internalMethod2' must have explicit '@differentiable' attribute to satisfy requirement instance method 'internalMethod2' (in protocol 'Protocol1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'Protocol1'}} {{3-3=@differentiable }}
41+
// expected-note @+2 {{candidate is missing explicit '@differentiable' attribute to satisfy requirement 'internalMethod2' (in protocol 'Protocol1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'Protocol1'}} {{3-3=@differentiable }}
4242
@differentiable(wrt: x)
4343
func internalMethod2(_ x: Float) -> Float {
4444
x
4545
}
4646

4747
// Error for missing `@differentiable` subset attribute.
48-
// expected-note @+2 {{instance method 'internalMethod3' must have explicit '@differentiable(wrt: x)' attribute to satisfy requirement instance method 'internalMethod3' (in protocol 'Protocol1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'Protocol1'}} {{3-3=@differentiable(wrt: x) }}
48+
// expected-note @+2 {{candidate is missing explicit '@differentiable(wrt: x)' attribute to satisfy requirement 'internalMethod3' (in protocol 'Protocol1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'Protocol1'}} {{3-3=@differentiable(wrt: x) }}
4949
@differentiable(wrt: (self, x))
5050
func internalMethod3(_ x: Float) -> Float {
5151
x

test/AutoDiff/Sema/ImplicitDifferentiableAttributeCrossFile/Inputs/other_file_protocol_default_implementation_witness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protocol P2: P1 {}
1010

1111
extension P2 {
1212
@differentiable(wrt: (self, input))
13-
// expected-note @+1 {{instance method 'callAsFunction' must have explicit '@differentiable(wrt: self)' attribute to satisfy requirement instance method 'callAsFunction' (in protocol 'P1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'P1'}}
13+
// expected-note @+1 {{candidate is missing explicit '@differentiable(wrt: self)' attribute to satisfy requirement 'callAsFunction' (in protocol 'P1') because it is declared in a different file than the conformance of 'ConformingStruct' to 'P1'}}
1414
public func callAsFunction(_ input: Float) -> Float {
1515
return input
1616
}

0 commit comments

Comments
 (0)