Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: invalid operation errors need to print expression #48472

Closed
rsc opened this issue Sep 19, 2021 · 6 comments
Closed

cmd/compile: invalid operation errors need to print expression #48472

rsc opened this issue Sep 19, 2021 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Sep 19, 2021

The new type checker no longer echoes the expression involved in an invalid operation. It should. The exact expression makes it eaiser for people to get their bearings when reading the error.

(The fine-grained position information might provide similar precision, but it requires tool support or character counting for humans to use.)

% cat x.go
package p

func g() {
	var s string
	var i int
	_ = s + i
}
% go tool compile x.go
x.go:6:6: invalid operation: mismatched types string and int
% go1.17 tool compile x.go
x.go:6:8: invalid operation: s + i (mismatched types string and int)
% 

/cc @griesemer @findleyr

@rsc rsc added this to the Go1.18 milestone Sep 19, 2021
@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 19, 2021
@gopherbot
Copy link

Change https://golang.org/cl/350929 mentions this issue: cmd/compile: print expression when invalid operation errors

gopherbot pushed a commit that referenced this issue Sep 27, 2021
For #48472

Change-Id: I5072ebcf53e03fb5515c51a2ad01f02d72b30719
Reviewed-on: https://go-review.googlesource.com/c/go/+/350929
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: David Chase <drchase@google.com>
@heschi
Copy link
Contributor

heschi commented Oct 6, 2021

Is this fixed?

@griesemer
Copy link
Contributor

This is in the process of being fixed. CLs are pending.

@ALTree
Copy link
Member

ALTree commented Oct 19, 2021

Another test case, bad error message at current tip:

$ gotip version
go version devel go1.18-ee92daae25 Tue Oct 19 07:45:46 2021 +0000 windows/amd64

$ cat test.go
package p

func f(i int) int {
        i += "1"
        return i
}

$ gotip tool compile -G=0 test.go
test.go:4:4: invalid operation: i += "1" (mismatched types int and untyped string)

$ gotip tool compile test.go
test.go:4:2: invalid operation: <nil> (mismatched types int and untyped string)

invalid operation: <nil>

@griesemer
Copy link
Contributor

Just to be clear: this is on our radar but may not be fixed before the freeze due to higher-priority items that are not just bug fixes. We will spend time on this during the freeze as needed because improving error messages is unlikely to destabilize the release.

@gopherbot
Copy link

Change https://golang.org/cl/357229 mentions this issue: cmd/compile: print assignment operation when invalid operation errors

@golang golang locked and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants