Skip to content

TCO does not trigger in case expressions with assign guards #3957

@radrow

Description

@radrow

Description

The compiler misses an opportunity for tail-call optimization when the self call happens inside a case clause guarded with assign (<-) expression.

To Reproduce

Compile module

module Test where

fixPokemonHp :: Int -> Int
fixPokemonHp x = case x of
  n | _ <- n -> fixPokemonHp x
  _ -> fixPokemonHp x

Expected behavior

Produce some tail recursive code

Actual behavior

// Generated by purs version 0.13.8
"use strict";
var fixPokemonHp = function (x) {
    var v = function (v1) {
        return fixPokemonHp(x);
    };
    return fixPokemonHp(x);
};
module.exports = {
    fixPokemonHp: fixPokemonHp
};

Additional context

btw I am using Arch Linux

Add any other context about the problem here.

PureScript version

0.13.8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions