Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SameLen on custom collections requires a suppressed warning to establish representation invariant #213

Open
kelloggm opened this issue Jan 25, 2018 · 1 comment

Comments

@kelloggm
Copy link
Owner

Typically this needs to happen in the constructor. For example, consider the following class:

class MyArray<T> {
    T @SameLen("this") [] backingArray;

    @SuppressWarnings("index") // establish representation invariant
    public MyArray(@NonNegative int length) {
         backingArray = new T[length];
    }
 
    public @LengthOf("this") int length() { return backingArray.length; }
    public T get(@IndexFor("this") int index) { return backingArray[index]; }
}

Ideally, this suppressed warning wouldn't be required. It's not really a false positive, so we should replace it with an annotation.

@mernst
Copy link
Collaborator

mernst commented Jan 25, 2018

Is an annotation needed, and if so which one? It would be nicer if the checker could had logic to permit an assignment to a @SameLen("this") field in the constructor (perhaps with some caveats).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants