Skip to content

Conversation

@aosen-xiong
Copy link

I tried with old PICO checker. Here is the following errors reported by PICO.

JavaExamples.java:10: error: [assignment.type.incompatible] incompatible types in assignment.
        @Mutable Set<String> new_s1 = s; // ERROR, type incompatible
                                      ^
  found   : @Initialized @Immutable Set<@Initialized @Immutable String>
  required: @UnknownInitialization @Mutable Set<@Initialized @Immutable String>
JavaExamples.java:11: error: [method.invocation.invalid] call to add(E) not allowed on the given receiver.
        new_s.add("x"); // ERROR
                 ^
  found   : @Initialized @Immutable Set</*INFERENCE FAILED for:*/ ? extends Object>
  required: @Initialized @Mutable Set</*INFERENCE FAILED for:*/ ? extends Object>
JavaExamples.java:18: error: [method.invocation.invalid] call to add(E) not allowed on the given receiver.
        new_s.add("x"); // ERROR
                 ^
  found   : @Initialized @Immutable Set</*INFERENCE FAILED for:*/ ? extends Object>
  required: @Initialized @Mutable Set</*INFERENCE FAILED for:*/ ? extends Object>
JavaExamples.java:38: error: [method.invocation.invalid] call to add(E) not allowed on the given receiver.
        p.family.add("Jenny"); // ERROR, can not mutate immut list
                    ^
  found   : @Initialized @Immutable List</*INFERENCE FAILED for:*/ ? extends Object>
  required: @Initialized @Mutable List</*INFERENCE FAILED for:*/ ? extends Object>
JavaExamples.java:56: error: [method.invocation.invalid] call to add(E) not allowed on the given receiver.
        this.family.add("Mom"); // ERROR
                       ^
  found   : @Initialized @Immutable List</*INFERENCE FAILED for:*/ ? extends Object>
  required: @Initialized @Mutable List</*INFERENCE FAILED for:*/ ? extends Object>
JavaExamples.java:64: error: [return.type.incompatible] incompatible types in return.
        return family; // ERROR, type incompatible
               ^
  type of expression: @Initialized @Immutable List<@Initialized @Immutable String>
  method return type: @Initialized @Mutable List<@Initialized @Immutable String>
6 errors

p.family.add("Jenny"); // ERROR, can not mutate immut list
}

// Type parameter mutability
Copy link
Author

Choose a reason for hiding this comment

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

@txiang61 Could you explain what foo3 try to do? The method invocation on Set is not right and the comment type parameter mutability should related generics, right?

Copy link
Member

@txiang61 txiang61 May 4, 2024

Choose a reason for hiding this comment

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

In this example I was just trying to say that the items in the Set are immutable, because there are no @Mutable before List.

Yes need checks on generic type parameters as well. Can you add this to the examples? Thanks!

class ImmutSet<T> {}

@Mutable class MutList<@Mutable T> {}

void foo(ImmutSet<MutList<T>> s) {  // ERROR 
}

void foo(MutList<ImmutSet<T>> s) {  // OK 
}

@aosen-xiong
Copy link
Author

Closed and use #48.

@aosen-xiong aosen-xiong closed this May 8, 2024
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

Successfully merging this pull request may close these issues.

3 participants