Skip to content

A function defined twice is silently the second one - #24

Merged
martin-k-m merged 1 commit into
mainfrom
docs/redefinition-is-silent
Sep 3, 2026
Merged

martin-k-m merged 1 commit into
mainfrom
docs/redefinition-is-silent

Conversation

@martin-k-m

Copy link
Copy Markdown
Collaborator
fn f() -> Str = "first"
fn f() -> Str = "second"
print(f())                 // second, with no diagnostic from either checker

Recorded in docs/BUGS.md under Open because it cost a real bug today. twill-lang/spool replaced two insertion sorts with calls to the new builtin and left the old bodies in the same files. Both files then defined the function twice, both kept running the insertion sort, and the tests, the source gate and CI all passed — nothing anywhere looks at whether a name is defined twice. The commit said four sorts had been replaced when two had. twill-lang/spool#4 is the correction.

A redefinition inside one file is almost always an edit that went wrong. There is no conditional compilation in this language, so the cases where somebody means it do not exist, which makes this cheap to diagnose with a false-positive rate of zero.

This PR only writes it down. Refusing it in the checker is the fix and is not written yet.

🤖 Generated with Claude Code

Neither checker says anything and the later definition wins. Recorded
because it cost a real bug an hour ago: spool replaced two insertion sorts
with calls to the new builtin, left the old bodies in the same files, and
both files kept running the insertion sort. Tests, source gate and CI all
passed, because nothing looks at whether a name is defined twice.

A redefinition inside one file is almost always an edit that went wrong.
There is no conditional compilation in this language, so the cases where
somebody means it do not exist, which makes this cheap to diagnose and the
false-positive rate zero. Refusing it in the checker is the obvious fix and
is not written yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@martin-k-m
martin-k-m merged commit 08b7c95 into main Sep 3, 2026
3 checks passed
@martin-k-m
martin-k-m deleted the docs/redefinition-is-silent branch September 3, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant