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

Comments

@rsc
Copy link
Contributor

@rsc 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

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 19, 2021

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 heschi commented Oct 6, 2021

Is this fixed?

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 6, 2021

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

@ALTree
Copy link
Member

@ALTree 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

@griesemer griesemer commented Oct 19, 2021

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

@gopherbot gopherbot commented Oct 20, 2021

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

@gopherbot gopherbot closed this in b091189 Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants