[go] go/types: better diagnostic for type shadowing

3 views
Skip to first unread message

Alan Donovan (Gerrit)

unread,
Dec 19, 2025, 5:08:30 PM (5 days ago) Dec 19
to goph...@pubsubhelper.golang.org, Go LUCI, Robert Griesemer, Robert Griesemer, Mark Freeman, golang-co...@googlegroups.com
Attention needed from Mark Freeman, Robert Griesemer and Robert Griesemer

Alan Donovan added 1 comment

File src/go/types/typexpr.go
Line 52, Patchset 2 (Parent): check.errorf(e, NotAType, "%s is not a type", obj.Name())
Robert Griesemer . unresolved

I would simply do this for now:

check.errorf(e, NotAType, "%s is not a type", obj)

This is good enough for this error.
As a separate and independent CL, I think we can improve error messages that print objects.

Alan Donovan

I tried that initially, but the error messages were rather unsatisfactory, for example:
```
a.go:5:8: var error error is not a type
```
or in more pathological cases,
```
a.go:5:8: var error func(int, string, bool) (error, []chan int) is not a type
```
Compare with the latest draft of this CL:
```
a.go:5:8: error is a local variable, not a type
a.go:4:6: declaration of error as local variable here shadows a type
```

Open in Gerrit

Related details

Attention is currently required from:
  • Mark Freeman
  • Robert Griesemer
  • Robert Griesemer
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ia3484998bb384ff570c20b6792cf8461c60aa38c
Gerrit-Change-Number: 731180
Gerrit-PatchSet: 4
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-CC: Robert Griesemer <g...@google.com>
Gerrit-Attention: Robert Griesemer <g...@google.com>
Gerrit-Attention: Robert Griesemer <g...@golang.org>
Gerrit-Attention: Mark Freeman <markf...@google.com>
Gerrit-Comment-Date: Fri, 19 Dec 2025 22:08:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Robert Griesemer <g...@google.com>
unsatisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Dec 19, 2025, 5:28:02 PM (5 days ago) Dec 19
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan, Mark Freeman, Robert Griesemer and Robert Griesemer

Alan Donovan uploaded new patchset

Alan Donovan uploaded patch set #5 to this change.
Following approvals got outdated and were removed:
  • TryBots-Pass: LUCI-TryBot-Result-1 by Go LUCI
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Mark Freeman
  • Robert Griesemer
  • Robert Griesemer
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ia3484998bb384ff570c20b6792cf8461c60aa38c
Gerrit-Change-Number: 731180
Gerrit-PatchSet: 5
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-CC: Robert Griesemer <g...@google.com>
Gerrit-Attention: Robert Griesemer <g...@google.com>
Gerrit-Attention: Robert Griesemer <g...@golang.org>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Attention: Mark Freeman <markf...@google.com>
unsatisfied_requirement
open
diffy

Robert Griesemer (Gerrit)

unread,
Dec 23, 2025, 3:11:40 PM (2 days ago) Dec 23
to Alan Donovan, goph...@pubsubhelper.golang.org, Go LUCI, Robert Griesemer, Mark Freeman, golang-co...@googlegroups.com
Attention needed from Alan Donovan, Mark Freeman and Robert Griesemer

Robert Griesemer added 1 comment

File src/go/types/typexpr.go
Line 52, Patchset 2 (Parent): check.errorf(e, NotAType, "%s is not a type", obj.Name())
Robert Griesemer . unresolved

I would simply do this for now:

check.errorf(e, NotAType, "%s is not a type", obj)

This is good enough for this error.
As a separate and independent CL, I think we can improve error messages that print objects.

Alan Donovan

I tried that initially, but the error messages were rather unsatisfactory, for example:
```
a.go:5:8: var error error is not a type
```
or in more pathological cases,
```
a.go:5:8: var error func(int, string, bool) (error, []chan int) is not a type
```
Compare with the latest draft of this CL:
```
a.go:5:8: error is a local variable, not a type
a.go:4:6: declaration of error as local variable here shadows a type
```

Robert Griesemer

Agreed it's better (for novices), but it's also very verbose compared to our typical error messages. I am just concerned that we're doing a one-off fix here instead of a more comprehensive review/fix.

I like the objectKind idea (in fact I played with a similar approach). Can we just do something like:

```
a.go:5:8: error (local variable) is not a type
```

That's more inline with what we have already in place.

Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Mark Freeman
  • Robert Griesemer
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ia3484998bb384ff570c20b6792cf8461c60aa38c
    Gerrit-Change-Number: 731180
    Gerrit-PatchSet: 5
    Gerrit-Owner: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Mark Freeman <markf...@google.com>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Robert Griesemer <g...@google.com>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Attention: Mark Freeman <markf...@google.com>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 20:11:36 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Robert Griesemer <g...@google.com>
    Comment-In-Reply-To: Alan Donovan <adon...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages