Macaulay2 / Macaulay2/M2

Installing a method on a plain function closure should be an error

Open
#4,511 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bugs directory Interpreter
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

This issue was triaged from [`bugs/dan/0-installing-methods-functions-on-function-closures`](https://github.com/Macaulay2/M2/blob/388c1ff0ce30d83751dea7bc7eac77fdc1305dd7/bugs/dan/0-installing-methods-functions-on-function-closures), one of the 857 files removed from the pre-GitHub `bugs/` tree by [`d2c8d27826`](https://github.com/Macaulay2/M2/commit/d2c8d27826) and catalogued in [#36](https://github.com/Macaulay2/M2/issues/36). **The commentary below was written by Claude (Claude Opus 5, via Claude Code)**, not by @d-torrance, whose account posted it -- please weigh it accordingly.

### The original file, verbatim

```text
Arrange for this to give an error message:

i3 : first List := x->x

o3 = {*Function[stdio:3:15-3:17]*}

o3 : FunctionClosure

It's not a method function!

i4 : first

o4 = first

o4 : FunctionClosure

i5 : code first

o5 = ../../../d/startup.m2.in:122:16-122:21: --source code:
first = x -> x#0;

Actually, this will interfere with all the code in typicalvalues.m2!
```

### Where it stands today

Still accepted silently:

```m2
i1 : first List := x -> x
o1 = {*Function[stdio:1:15-1:17]*}
o1 : FunctionClosure
```

`first` is a plain function closure (`startup.m2`: `first = x -> x#0`), not a method function, so
there is no method table for the assignment to write into. Nothing is installed and nothing is said.

### The complication the file names itself

Dan's own last line is the obstacle: *"Actually, this will interfere with all the code in
typicalvalues.m2!"* That file installs typical values by assigning to keys on functions that are not
method functions, so an error here would break the mechanism M2 uses to record return types. Any fix
has to distinguish "installing a typical value on a closure", which is intentional and widespread,
from "installing a method on a closure", which is the mistake being reported.

### Related, from the opposite direction

**#1979** proposes typed function closures — wanting the *capability* this file wants an error for. So
the two issues disagree about the destination, and it is worth deciding which before either is
implemented.

`open` · disposition `issue` · source of truth: [`bug-triage/catalog.tsv`](https://github.com/d-torrance/M2/blob/bug-triage/bug-triage/catalog.tsv)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the plain-closure assignment shown in the issue and inspect startup.m2, where first is defined, alongside typicalvalues.m2, which relies on assignments to function keys. Review #1979 before deciding whether the behavior should distinguish method installation from intentional typical-value recording; done means the intended case errors without breaking typicalvalues.m2.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.