Skip to content

Invalid polymorphic code accepted #549

@erszcz

Description

@erszcz

The following code is correctly rejected by Gradualizer:

-spec poly_2(fun((A) -> A)) -> {integer(), boolean()}.
poly_2(F) -> {F(42), F(false)}.

However, the following code is not rejected:

-spec poly_2(fun((A) -> A)) -> {integer(), integer()}.
poly_2(F) -> {F(42), F(84)}.

while by itself it seems harmless. We could argue whether the above code is valid or not based on polymorphism rank we'd like to support (rank-1 - invalid, rank-2 - valid). However, an invalid application like the following should be rejected in any case, whereas it's not:

-gradualizer([solve_constraints]).

-spec poly_2(fun((A) -> A)) -> {integer(), integer()}.
poly_2(F) -> {F(42), F(84)}.

-spec take_boolean(boolean()) -> boolean().
take_boolean(B) -> B.

-spec should_be_rejected() -> {integer(), integer()}.
should_be_rejected() ->
    poly_2(fun take_boolean/1).

See WhatsApp/eqwalizer#33 for the original issue where this was spotted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions