Skip to content

Commit

Permalink
don't show a deprecation message if the user has key and some other c…
Browse files Browse the repository at this point in the history
…omparator special method

Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Sep 3, 2024
1 parent 23295bd commit c87f508
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
18 changes: 9 additions & 9 deletions modules/standard/Sort.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,6 @@ proc chpl_check_comparator(comparator,
}
// Check for valid comparator methods
else if canResolveMethod(comparator, "key", data) {
if doDeprecationCheck && !comparatorImplementsKey(comparator) {
param atType = if isRecord(comparator) then "record" else "class";
param fixString = "'" + atType + " " +
comparator.type:string + ": keyComparator'";
compilerWarning(errorDepth=errorDepth,
"Defining a comparator with a 'key' method without " +
"implementing the keyComparator interface is deprecated. " +
"Please implement the keyComparator interface (i.e. " + fixString + ").");
}
// Check return type of key
const keydata = comparator.key(data);
type keytype = keydata.type;
Expand All @@ -484,6 +475,15 @@ proc chpl_check_comparator(comparator,
comparator.type:string,
" contains both a key method and a keyPart method");
}
if doDeprecationCheck && !comparatorImplementsKey(comparator) {
param atType = if isRecord(comparator) then "record" else "class";
param fixString = "'" + atType + " " +
comparator.type:string + ": keyComparator'";
compilerWarning(errorDepth=errorDepth,
"Defining a comparator with a 'key' method without " +
"implementing the keyComparator interface is deprecated. " +
"Please implement the keyComparator interface (i.e. " + fixString + ").");
}
}
else if canResolveMethod(comparator, "compare", data, data) {
if doDeprecationCheck {
Expand Down
2 changes: 0 additions & 2 deletions test/library/standard/Sort/errors/errors-comparator.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ proc keyPartArgs.keyPart(a) {
return a;
}

// this should still get a deprecation warning
// Both key and compare
record keyAndCompare { }
proc keyAndCompare.key(a) {
Expand All @@ -61,7 +60,6 @@ proc keyAndCompare.compare(a, b) {
return 0;
}

// this should still get a deprecation warning
// Both key and keyPart
record keyAndKeyPart { }
proc keyAndKeyPart.key(a) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
errors-comparator.chpl:9: In function 'main':
errors-comparator.chpl:17: warning: Defining a comparator with a 'key' method without implementing the keyComparator interface is deprecated. Please implement the keyComparator interface (i.e. 'record keyAndCompare: keyComparator').
errors-comparator.chpl:17: error: keyAndCompare contains both a key method and a compare method
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
errors-comparator.chpl:9: In function 'main':
errors-comparator.chpl:17: warning: Defining a comparator with a 'key' method without implementing the keyComparator interface is deprecated. Please implement the keyComparator interface (i.e. 'record keyAndKeyPart: keyComparator').
errors-comparator.chpl:17: error: keyAndKeyPart contains both a key method and a keyPart method

0 comments on commit c87f508

Please sign in to comment.