Skip to content

enh(go) add the predeclared identifiers any, comparable, min, max and clear - #4553

Open
yu2971512385-ui wants to merge 1 commit into
highlightjs:mainfrom
yu2971512385-ui:fix/go-predeclared-identifiers
Open

yu2971512385-ui wants to merge 1 commit into
highlightjs:mainfrom
yu2971512385-ui:fix/go-predeclared-identifiers

Conversation

@yu2971512385-ui

Copy link
Copy Markdown

Changes

The Go grammar's TYPES list carries the predeclared types (bool, byte, error, string, …) but not any and comparable, which Go 1.18 added alongside generics, and BUILT_INS predates clear, max and min from Go 1.21. All five are predeclared identifiers in the spec, exactly like the entries already in those two lists (which are likewise shadowable — len, copy, new, delete).

Before → after on ordinary modern Go:

code before after
var data map[string]any any unstyled hljs-type
func process(in any) any any unstyled hljs-type
type Set[E comparable] map[E]struct{} comparable unstyled hljs-type
lo := min(1, 2) min unstyled hljs-built_in
clear(data) clear unstyled hljs-built_in

Note the type parameter list of a function declaration (func Index[E comparable](…)) is consumed by the existing function/title mode and is unaffected by this change; that is a separate pre-existing quirk and I left it alone to keep this focused.

Checklist

  • Added markup tests (test/markup/go/predeclared-identifiers.txt) — it fails on main and passes with the change; mocha test is green (1651 passing, 3 pending), npm run lint-languages clean.
  • I have read and followed our AI-assisted contributions policy (human review, no slop). The gap was found by lexing modern-language snippets and looking for identifiers that stay unstyled; the commit carries Assisted-by: Claude Opus 5 (high) and I reviewed and tested every line.

🤖 Generated with Claude Code

… clear

The type list already carries the predeclared types (bool, byte, error,
string, ...) but not any and comparable, which Go 1.18 added along with
generics, and the built-in list predates the clear, max and min functions
of Go 1.21. All five are predeclared identifiers in the language spec,
like the entries already in those lists.

Assisted-by: Claude Opus 5 (high)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants