diff --git a/gopls/internal/golang/semtok.go b/gopls/internal/golang/semtok.go index e008d8cda..4e24dafc2 100644 --- a/gopls/internal/golang/semtok.go +++ b/gopls/internal/golang/semtok.go @@ -556,7 +556,7 @@ func (tv *tokenVisitor) ident(id *ast.Ident) { case *types.Builtin: emit(semtok.TokFunction, "defaultLibrary") case *types.Const: - if is[*types.Named](obj.Type()) && + if is[*types.Basic](obj.Type()) && (id.Name == "iota" || id.Name == "true" || id.Name == "false") { emit(semtok.TokVariable, "readonly", "defaultLibrary") } else { diff --git a/gopls/internal/test/marker/testdata/token/builtin_constant.txt b/gopls/internal/test/marker/testdata/token/builtin_constant.txt new file mode 100644 index 000000000..8f0c021b3 --- /dev/null +++ b/gopls/internal/test/marker/testdata/token/builtin_constant.txt @@ -0,0 +1,21 @@ +This test checks semanticTokens on builtin constants. +(test for #70219.) + +-- settings.json -- +{ + "semanticTokens": true +} + +-- flags -- +-ignore_extra_diags + +-- default_lib_const.go -- +package p + +func _() { + a, b := false, true //@ token("false", "variable", "readonly defaultLibrary"), token("true", "variable", "readonly defaultLibrary") +} + +const ( + c = iota //@ token("iota", "variable", "readonly defaultLibrary") +)