Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.checkerframework.checker.index.samelen;

import org.checkerframework.common.basetype.BaseTypeChecker;
import org.checkerframework.framework.qual.RelevantJavaTypes;
import org.checkerframework.framework.source.SuppressWarningsPrefix;

/**
Expand All @@ -10,7 +9,9 @@
*
* @checker_framework.manual #index-checker Index Checker
*/
@RelevantJavaTypes({CharSequence.class, Object[].class, Object.class})
// This @RelevantJavaTypes annotation is incorrect, because @SameLen can apply to an arbitrary
// user-defined datatype: https://checkerframework.org/manual/#index-annotating-fixed-size .
// @RelevantJavaTypes({CharSequence.class, Object[].class, Object.class})
@SuppressWarningsPrefix({"index", "samelen"})
public class SameLenChecker extends BaseTypeChecker {
/** Create a new SameLenChecker. */
Expand Down
10 changes: 7 additions & 3 deletions checker/tests/index/SameLenIrrelevant.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// Tests that adding an @SameLen annotation to a primitive type is still
// an error.

// All the errors in this test case are disabled. They were issued when `@SameLen` was restricted
// to arrays and CharSequence, but @SameLen can be written on an arbitrary user-defined type:
// https://checkerframework.org/manual/#index-annotating-fixed-size .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better for these errors, which are on primitive types, to be preserved: @SameLen is fine on array, CharSequences, and user-defined types, but it does not make sense on primitives.

Is there a way to use @RelevantJavaTypes to express that? Maybe it needs to be done procedurally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that behavior is desirable. There is not a way for @RelevantJavaTypes to express that fact. We could add such a mechanism, or we could enforce the constraint procedurally. I think those belong in a different pull request than this one, which exists to unblock #6254.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not a way for @RelevantJavaTypes to express that fact

Thanks for confirming. We can address it in a later PR.


import org.checkerframework.checker.index.qual.SameLen;

public class SameLenIrrelevant {
// :: error: (anno.on.irrelevant)
// NO :: error: (anno.on.irrelevant)
public void test(@SameLen("#2") int x, int y) {
// do nothing
}

// :: error: (anno.on.irrelevant)
// NO :: error: (anno.on.irrelevant)
public void test(@SameLen("#2") double x, double y) {
// do nothing
}

// :: error: (anno.on.irrelevant)
// NO :: error: (anno.on.irrelevant)
public void test(@SameLen("#2") char x, char y) {
// do nothing
}
Expand Down