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: conversion error is a bit inaccurate #23394

Open
hirochachacha opened this Issue Jan 10, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@hirochachacha
Contributor

hirochachacha commented Jan 10, 2018

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package main

func main() {
	s := "s"
	_ = 'r' != s
	_ = 1 != s
	_ = 1.1 != s
}

What did you expect to see?

I expected to see "untyped rune", "untyped int", "untyped float".

What did you see instead?

"type untyped number" which is not a searchable keyword in the https://golang.org/ref/spec.

# command-line-arguments
./k.go:5:10: cannot convert 'r' (type untyped number) to type string
./k.go:5:10: invalid operation: 'r' != s (mismatched types rune and string)
./k.go:6:8: cannot convert 1 (type untyped number) to type string
./k.go:6:8: invalid operation: 1 != s (mismatched types int and string)
./k.go:7:10: cannot convert 1.1 (type untyped number) to type string
./k.go:7:10: invalid operation: 1.1 != s (mismatched types float64 and string)

To be precise, conversion error here is already inaccurate.
The error message implies s := string('r') is incorrect code, but it's not true.
Also "type untyped" is redundant expression to me.

cannot compare 'r' (untyped rune) to string

or

cannot assign 'r' (untyped rune) to string

is correct one. (initial one is better in this context)

Does this issue reproduce with the latest release (go1.9.2)?

I can see the conversion error, but I can't see "untyped number" in the error message.

System details

go version devel +23aefcd9ae Wed Jan 10 00:00:40 2018 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hiro/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTMPDIR=""
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build157306342=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version devel +23aefcd9ae Wed Jan 10 00:00:40 2018 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +23aefcd9ae Wed Jan 10 00:00:40 2018 +0000
uname -v: Darwin Kernel Version 17.3.0: Thu Nov  9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.2
BuildVersion:	17C88
lldb --version: lldb-900.0.64
  Swift-4.0
gdb --version: GNU gdb (GDB) 8.0.1
@odeke-em

This comment has been minimized.

Member

odeke-em commented Jan 10, 2018

Thank you @hirochachacha for this report!

For the record, to be more explicit this seems like a regression in the error message, the results are:

Go1.9.2

https://play.golang.org/p/TYPAMUyqiEI

prog.go:5:10: cannot convert 'r' to type string
prog.go:5:10: invalid operation: 'r' != s (mismatched types rune and string)
prog.go:6:8: cannot convert 1 to type string
prog.go:6:8: invalid operation: 1 != s (mismatched types int and string)
prog.go:7:10: cannot convert 1.1 to type string
prog.go:7:10: invalid operation: 1.1 != s (mismatched types float64 and string)

Go1.10beta* and tip are

./prog.go:5:10: cannot convert 'r' (type untyped number) to type string
./prog.go:5:10: invalid operation: 'r' != s (mismatched types rune and string)
./prog.go:6:8: cannot convert 1 (type untyped number) to type string
./prog.go:6:8: invalid operation: 1 != s (mismatched types int and string)
./prog.go:7:10: cannot convert 1.1 (type untyped number) to type string
./prog.go:7:10: invalid operation: 1.1 != s (mismatched types float64 and string)

and diffing

--- before	2018-01-09 23:56:03.000000000 -0800
+++ after	2018-01-09 23:56:10.000000000 -0800
@@ -1,6 +1,6 @@
-prog.go:5:10: cannot convert 'r' to type string
+prog.go:5:10: cannot convert 'r' (type untyped number) to type string
 prog.go:5:10: invalid operation: 'r' != s (mismatched types rune and string)
-prog.go:6:8: cannot convert 1 to type string
+prog.go:6:8: cannot convert 1 (type untyped number) to type string
 prog.go:6:8: invalid operation: 1 != s (mismatched types int and string)
-prog.go:7:10: cannot convert 1.1 to type string
+prog.go:7:10: cannot convert 1.1 (type untyped number) to type string
 prog.go:7:10: invalid operation: 1.1 != s (mismatched types float64 and string)

and I can confirm that this CL https://go-review.googlesource.com/46912 aka commit d05a123 is the source of the regression when we changed the print verb to %L from %v in this line
d05a123#diff-9d35af26b63e3e6b782e46da7441af82R411
screen shot 2018-01-10 at 12 01 23 am

/cc @kshvmdn and @griesemer

@griesemer

This comment has been minimized.

Contributor

griesemer commented Jan 11, 2018

Thanks @odeke-em for the analysis.

For the record, gotype reports three errors:

x.go:5:6: cannot convert 'r' (untyped rune constant 114) to string
x.go:6:6: cannot convert 1 (untyped int constant) to string
x.go:7:6: cannot convert 1.1 (untyped float constant) to string

@griesemer griesemer self-assigned this Jan 11, 2018

@griesemer griesemer added this to the Go1.11 milestone Jan 11, 2018

@griesemer

This comment has been minimized.

Contributor

griesemer commented May 31, 2018

The error messages could be better, but there are error messages. Not urgent. Moving to unplanned.

@griesemer griesemer modified the milestones: Go1.11, Unplanned May 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment