Skip to content

Polymorphism not dispatched correctly in field assignment #222

@jwaataja

Description

@jwaataja

I have the following code.

import org.checkerframework.checker.determinism.qual.*;
import java.util.*;

public class C {
    public @Det C myField = new @Det C(new @Det ArrayList<>());

    public C(@PolyDet List<@PolyDet String> list) {
    }
}

In the constructor call in the field assignment, @PolyDet should be resolved to @Det, but I get an error message indicating this is not the case.

C.java:5: error: [argument.type.incompatible] incompatible argument for parameter list of C.
    public @Det C myField = new @Det C(new @Det ArrayList<>());
                                       ^
  found   : @Det ArrayList<@PolyDet String>
  required: @PolyDet List<@PolyDet String>
C.java:5: error: [argument.type.incompatible] incompatible argument for parameter list of C.
    public @Det C myField = new @Det C(new @Det ArrayList<>());
                                       ^
  found   : @Det ArrayList<@PolyDet String>
  required: @PolyDet List<@PolyDet String>

Since the parameter to the constructor call is @Det, the @PolyDet should be resolved to @Det. This doesn't seem to occur for other type systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions