Skip to content

REPL: a call on a later line gets no instance of a generic function from an earlier line #354

Open

Description

@timfennis

A generic function gets one instance per set of argument types it's called with, compiled with its declaration. A function declared on an earlier REPL line was compiled already, so a later line's call uses its own body, which picks its overloads as the program runs. With an Any argument the call is typed by the overloads that take Any, while the body picks by the value:

> fn pick(x: Int) => 1; fn pick(x: Any) => "fallback"; fn wrap(x) => pick(x);
> let a: Any = 1; let s: String = wrap(a); print(s);
1
> print(s ++ "!");
error: ... ++

In one batch this prints fallback (#353). The fix is for a later line to compile the instances it needs of an earlier line's function, which needs that function's body and analysis to outlive its batch.

Found by Codex on #353.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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