Skip to content

Manifold fails to infer generic type when constructor uses optional parameters #65

@EotT123

Description

@EotT123

When using optional parameters in the constructor of a generic class, Manifold fails to correctly infer the generic type during instantiation. This leads to type inference errors in IntelliJ, even though the generic type is explicitly declared on the variable.

public static class MyClass<T> {
    private T t;
    public MyClass(T t=null, int i=5) {
        this.t = t;
    }
}
MyClass<String> myClass = new MyClass<>(i:3); // IntelliJ error: Incompatible equality constraint: String and Object
Image

This suggests that the type T is inferred as Object instead of String when the optional parameter t is omitted.

As a workaround, manually adding the type resolves the issue: MyClass<String> myClass = new MyClass<String>(i:3);
However, this results in another IntelliJ error: Cannot resolve constructor 'MyClass($constructor_<Object>)'

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions