roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.17k stars 294 forks source link

Error when defining an ability with a function that returns a lambda #6629

Open Karakatiza666 opened 5 months ago

Karakatiza666 commented 5 months ago

Steps to reproduce

Minimal steps to reproduce so far (requires multiple files to reproduce):

Show.roc

interface Show
    exposes [Show, show]
    imports [
    ]

Show implements
    show : a -> Str where a implements Show

Types.roc

interface Types
    exposes [PipelineStatus, pipelineStatus]
    imports [
        Show.{ Show, show },
        Enum.{ showEnum },
    ]

PipelineStatus := [
    Shutdown,
    Running,
]
    implements [
        Eq,
        Show { show: showPipelineStatus },
    ]
valuesPipelineStatus = [
    (@PipelineStatus Shutdown, "Shutdown"),
    (@PipelineStatus Running, "Running"),
]
showPipelineStatus = showEnum valuesPipelineStatus
pipelineStatus = \x -> @PipelineStatus x

expect
    show (pipelineStatus Running) == "Running"

Enum.roc

interface Enum
    exposes [
        showEnum,
    ]
    imports [
    ]

showEnum = \values -> \enum ->
        when
            List.findFirst values \pair -> enum == pair.0
        is
            Ok pair -> pair.1
            Err err -> crash (Inspect.toStr err)

main.roc

app "simple-enum"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
    }
    imports [
        pf.Stdout,
        Show.{ Show, show, pipelineStatus },
        Types.{ pipelineStatus },
    ]
    provides [main] to pf

main =
    show (pipelineStatus Running) |> Stdout.line

roc run yields

thread 'main' panicked at 'Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x11\x00\x00\x00\x00\x00\x00\x00t\xebz\x14\xc2\x8d\x90\xb5"), definition of value binding ValueId(4): expected type '((heap_cell,),)', found type '((heap_cell, bag<((heap_cell,), ())>),)'', crates/compiler/gen_llvm/src/llvm/build.rs:5759:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

roc test yields

thread '<unnamed>' panicked at 'Cannot find a partial proc for LambdaName { name: `40.IdentId(2)`, niche: Niche(Captures([InLayout(27)])) }', crates/compiler/mono/src/ir.rs:3193:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Workaround

The issue does not reproduce if you replace

showPipelineStatus = showEnum valuesPipelineStatus

with

showPipelineStatus = \ enum -> (showEnum valuesPipelineStatus) enum
ayazhafiz commented 5 months ago

This is a case of #3724